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

    Thank you Darrel,

    I will add the new code to my program and report the results.

    On the refreshing the big_number question:
    I’m using a Viniculun device to read an USB storage media that lets me read one byte at the time, n bytes or the entire file in one shot.
    The very first line in my data .txt file is the total number of records, 0 - 2,000,000, in fixed length (10 digit left padded with zeros.I used 10 digits to allow for up to 31 bit numbers if need be in the future), decimal format. The rest of the file are the records in fixed length (78 bytes) starting with "#" character, right padded with "~" character and ending with CR/LF. The data is only numerical and I do not process it, I just pass it to the Hserout. Every few records I must pause about 1 second to let the receiver process the information.

    I can read the 10 digit number byte by byte, strip the leading zeros and transfer into my big_number variable. How am I going to do it? This is the $10,000,000 question.

    I will fix my code right the way and work on the other problem.

    I must commend you guys for taking my “what if?” question and make sure I get the best solution. I learned a lot with your help.

    Regards,

    Nick
    Last edited by Nicmus; - 26th January 2008 at 01:55. Reason: Add more info

  2. #2


    Did you find this post helpful? Yes | No

    Default

    I added the changes Darrel suggested and it all works fine.
    I need to make small changes to the code to better fit my application and i will post it tomorrow.

    Thanks again and good night!

    Nick

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


    Did you find this post helpful? Yes | No

    Default

    If you come back and have it counting from 0 to <strike>1,000,000</strike> File Length ...

    I will ..., uh ...,

    oh hell, I don't know what I'd do.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Sorry for the delay. I had some hardware problems which I had to fix.
    Also I’m using a USB to serial interface to communicate with HT and every now and then Windows will see my device as a mouse.
    Here is what I have so far:
    I am able to count down and send out the big_number. I made few changes to your code to format the output as a 8 digit number (kept the leading zeros).
    I’m also receiving the big_number as two 4 digit decimal numbers.
    The only thing left is to make one big_number from the two word size variable (in_high and in_low).
    I was thinking to use your PutMultResult?D macro Din but I’m not quite sure how to do it.
    Here is the latest working code:

    INCLUDE "modedefs.bas"
    @ device pic16F876a,hs_osc,pwrt_on, protect_on
    DEFINE OSC 16
    DEFINE LOADER_USED 1
    DEFIne HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 4800
    define HSER_CLROERR 1

    HighDigits VAR WORD
    LowDigits VAR WORD
    big_number VAR WORD[2] ; 32-bit variable
    in_low var word
    in_high var word
    led var PORTA.2

    ADCON1=6
    CMCON=7

    ASM
    MOVE?CN macro Cin, Nout
    MOVE?CW Cin & 0xFFFF, Nout ; Low Word
    MOVE?CW (Cin >> 16), Nout + 2 ; High Word
    endm
    ENDASM
    ASM
    PutMulResult?N macro Nin
    MOVE?WW Nin, R2
    MOVE?WW Nin + 2, R0
    endm
    ENDASM
    pause 10000 ' Allow for the USB device to enumerate
    hserout [13,10,"Waiting for Big_number",13,10] ' Add time out later
    hserin [dec4 in_high,dec4 in_low]
    main:
    @ MOVE?CN 20000, _big_number
    WHILE (big_number[1] > 0) OR (big_number[0] > 0)
    big_number[0] = big_number[0] - 1
    IF big_number[0] = $ffff THEN big_number[1] = big_number[1] - 1
    @ PutMulResult?N _big_number
    GOSUB SendBigNum
    toggle led ' Show if any action
    WEND
    pause 5000
    goto main
    SendBigNum:
    HighDigits = DIV32 10000
    LowDigits = R2
    'IF (HighDigits > 0) THEN
    HSEROUT [DEC4 HighDigits, DEC4 LowDigits," and ",dec4 in_high,dec4 in_low,13,10]
    'ELSE
    'HSEROUT [DEC4 LowDigits,13,10]
    'ENDIF
    RETURN

    End

    Thanks again for your patience.

    Nick

    BTW: I'm practising to post code the right way.
    Last edited by Nicmus; - 26th January 2008 at 17:02. Reason: Posting code practice

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


    Did you find this post helpful? Yes | No

    Default

    I’m also receiving the big_number as two 4 digit decimal numbers.
    The only thing left is to make one big_number from the two word size variable (in_high and in_low).
    This one I'm not so sure about. And I don't have anything handy to test it on.
    I'm pretty sure it will work, but not Positive...
    Code:
    HighDigits = 100   ; Simulating File Length of 1,000,000
    LowDigits  = 0000
    
    big_number[0] = HighDigits * 10000
    big_number[1] = R0
    big_number[0] = big_number[0] + LowDigits
    IF (big_number[0] < LowDigits) THEN big_number[1] = big_number[1] + 1
    P.S. To put code in a scrolling box that doesn't scrunch it all to the left, use ...
    [code]' --- code goes here ---[/code]

    oops, nevermind. I see you're even using colors in the test area.
    <br>
    Last edited by Darrel Taylor; - 26th January 2008 at 22:39. Reason: oops
    DT

  6. #6


    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

  7. #7
    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

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