Retrieving 32bit Multiply Result


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    I’m a bit confused by your last post.
    I’m not sure were to add this code. Also I have the feeling that the big_number[0] and big_number[1] are switched from the way they are in my code.

    Here is the code in “colors” format:

    Code:
    <font color="#000000"><b>INCLUDE </b><font color="#FF0000">&quot;modedefs.bas&quot;
    </font><font color="#008000">@	device  pic16F876a,hs_osc,pwrt_on, protect_on
    </font><b>DEFINE </b>OSC 16
    <b>DEFINE</b>	LOADER_USED	1
    <b>DEFINE </b>HSER_RCSTA 90h
    <b>DEFINE </b>HSER_TXSTA 20h
    <b>DEFINE </b>HSER_BAUD 4800
    <b>DEFINE </b>HSER_CLROERR 1
    
    HighDigits  <b>VAR     WORD
    </b>LowDigits   <b>VAR     WORD
    </b>big_number  <b>VAR     WORD</b>[2]   <font color="#000080"><i>; 32-bit varia
    </i></font>in_low      <b>VAR     WORD
    </b>in_high     <b>VAR     WORD
    </b>led         <b>VAR     </b>PORTA.2
    
    ADCON1=6
    CMCON=7	
    
    <b>ASM  
    </b><font color="#008000">MOVE?CN  macro Cin, Nout
        MOVE?CW  Cin &amp; 0xFFFF, Nout     </font><font color="#000080"><i>; Low Word
        </i></font><font color="#008000">MOVE?CW  (Cin &gt;&gt; 16), Nout + 2  </font><font color="#000080"><i>; High Word
      </i></font><font color="#008000">endm
    </font><b>ENDASM
    ASM
    </b><font color="#008000">PutMulResult?N  macro Nin
        MOVE?WW  Nin, R2
        MOVE?WW  Nin + 2, R0
      endm
    </font><b>ENDASM
        PAUSE </b>1000
        <b>HSEROUT </b>[13,10,<font color="#FF0000">&quot;Waiting for Big_number&quot;</font>,13,10]
        <b>HSERIN </b>[<b>DEC4 </b>in_high,<b>DEC4 </b>in_low]
    
    main:
    <font color="#008000">@   MOVE?CN  20000, _big_number
    </font><b>WHILE </b>(big_number[1] &gt; 0) <b>OR </b>(big_number[0] &gt; 0)
        big_number[0] = big_number[0] - 1
        <b>IF </b>big_number[0] = $ffff <b>THEN </b>big_number[1] = big_number[1] - 1
    <font color="#008000">@   PutMulResult?N  _big_number
        </font><b>GOSUB </b>SendBigNum
        <b>TOGGLE </b>led
    <b>WEND
        PAUSE </b>5000
        <b>GOTO </b>main
    SendBigNum:
        HighDigits = <b>DIV32 </b>10000
        LowDigits  = R2
        <font color="#000080"><i>'IF (HighDigits &gt; 0) THEN
            </i></font><b>HSEROUT </b>[<b>DEC4 </b>HighDigits, <b>DEC4 </b>LowDigits,<font color="#FF0000">&quot; and &quot;</font>,<b>DEC4 </b>in_high,<b>DEC4 </b>in_low,13,10]
        <font color="#000080"><i>'ELSE
            'HSEROUT [DEC4 LowDigits,13,10]
        'ENDIF
    </i></font><b>RETURN
    
    END
    </b>
    How do I process the in_low and in_high variables to get the big_number before entering the main loop?
    Am I pulling them right as DEC4 or should I do it differently?

    Regards,

    Nick

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Sorry. Should have used your variable names ...
    Code:
    big_number[0] = in_high * 10000
    big_number[1] = R0
    big_number[0] = big_number[0] + in_low
    IF (big_number[0] < in_low) THEN big_number[1] = big_number[1] + 1
    Just stick it after the HSERIN.

    P.S. Nice "Colors".
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    I added your last lines and had to REM the line:

    Code:
    @   MOVE?CN  1000000, _big_number
    After that everything works as intended.
    I guess the macro this line was pointing to is no longer needed.
    I will open an other thread with a question on detecting EOF.
    There are no words to thank you enough for your help.

    Best Regards,

    Nick

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yup, that statement/macro is no longer needed.

    EOF marker for a .txt file is usually 26. That's a byte with the decimal value 26.
    In hex it's 1A, ASCII it's ctrl-Z, whichever way you want to look at it.

    Of course that ruins everything we just did.

    And you're welcome.
    <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Not really.
    For now what we did will work just fine and buys me time.
    But, and I’m sure you are the same way, if it can be improved, and you know it can, loosing few more hours of sleep doesn’t really matter. It will be a future project as I explained in my new post “Detecting EOF” (I will learn how to insert a link, I promise!)

    It’s just like the CC commercial:
    “The smile on your face after getting it done right…………Priceless “

    Thousands of thanks again.

    Nick

  6. #6


    Did you find this post helpful? Yes | No

    Default the same way you entered [code]

    to add a link [URL]past link here[/URL] .

    for example, [URL]http://www.picbasic.co.uk/forum/misc.php?do=bbcode[/URL]
    adds this link http://www.picbasic.co.uk/forum/misc.php?do=bbcode ,
    which is the link to the codes available and their usage.
    (the "vB code" link near the bottom of the page)


    there's also [THREAD] and [POST] codes, and other options to make it look all special. example:

    click here for viagra!!

    which takes you to your post I'm replying to, is done with:
    [post=49767]click here for [size=+3][color=purple]viagra!![/color][/size][/post]

    As you can see I'm really bored, but I'll stop wasting your time now.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Having fun and learning is my kind of treat.
    Thanks Nomad for the crash course on posting links.

    Nick

Similar Threads

  1. Strugling without floating point
    By pjsmith in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th March 2011, 07:29
  2. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 15:45
  3. 32-bit Variables and DIV32, Hourmeter 99999.9
    By Darrel Taylor in forum Code Examples
    Replies: 9
    Last Post: - 23rd November 2006, 08:23
  4. PBP 16-bit ADC result math
    By sonic in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2005, 15:21
  5. Retrieving Div32 Remainder
    By Darrel Taylor in forum Code Examples
    Replies: 4
    Last Post: - 20th August 2003, 04:53

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts