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 have a PBP copy installed on my work computer so I tried your code in a simple program to send out numbers (if I understood you correctly) from Big_number to 0.

    I am using:
    MCS 2.3.0.0
    PBP 2.47
    MPASM 5.03

    This is the small program I’m trying to compile but I get a warning and an error:

    INCLUDE "modedefs.bas"
    DEFINE OSC 16
    DEFINE LOADER_USED 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 4800
    DEFINE HSER_CLROERR 1

    big_number VAR WORD[2] ; 32-bit variable

    ADCON1=6
    CMCON=7

    main:

    @ MOVE?CN 1000000, big_number
    WHILE (big_number[1] > 0) OR (big_number[0] > 0)
    HSEROUT [#big_number[1],#big_number[0]]
    big_number[0] = big_number[0] - 1
    IF big_number[0] = $ffff THEN big_number[1] = big_number[1] - 1
    WEND
    pause 5000
    goto main
    ASM
    ;---[load a 32-bit constant into a 32-bit variable]-----------------
    MOVE?CN macro Cin, Nout
    MOVE?CW Cin & 0xFFFF, Nout ; Low Word
    MOVE?CW (Cin >> 16), Nout + 2 ; High Word
    endm
    ENDASM
    End


    The messages I get are:

    Warning[207] c:\big_num.asm 99: Found label after column 1.(MOVE?CN)
    Error[108] c:\big_num.asm : Illegal character (1)

    Any idea?

    Regards,

    Nick

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Put the macro in the source code BEFORE the actual usage.

    INCLUDE "modedefs.bas"
    DEFINE OSC 16
    DEFINE LOADER_USED 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 4800
    DEFINE HSER_CLROERR 1
    big_number VAR WORD[2] ; 32-bit variable
    ADCON1=6
    CMCON=7
    goto main
    ASM
    ;---[load a 32-bit constant into a 32-bit variable]-----------------
    MOVE?CN macro Cin, Nout
    MOVE?CW Cin & 0xFFFF, Nout ; Low Word
    MOVE?CW (Cin >> 16), Nout + 2 ; High Word
    endm
    ENDASM
    main:
    @ MOVE?CN 1000000, big_number
    WHILE (big_number[1] > 0) OR (big_number[0] > 0)
    HSEROUT [#big_number[1],#big_number[0]]
    big_number[0] = big_number[0] - 1
    IF big_number[0] = $ffff THEN big_number[1] = big_number[1] - 1
    WEND
    pause 5000
    goto main
    End
    [/code]

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Skimask,

    I tried that first but I got 12 errors:

    Error[113] c:\pbp\pbppicbasic14.lib428 : Symbol not previously defined (big_number).
    Should I do any changes in pbppicbasic14.lib?
    Thanks,

    Nick

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    edit this line
    Code:
    @ MOVE?CN 1000000, big_number
    to
    Code:
    @ MOVE?CN 1000000, _big_number
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    OOps!

    Thanks Steve.
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thank you Darrel, Steve and Skimask,

    No more errors.
    One more clarification on the line:
    @ MOVE?CN 1000000, _big_number
    Does it make my big_number=1000000 in decimal?
    If that is true should I see the counter going down from 1000000 to 0?
    Am I processing the big_number right in my HSEROUT statement because when I run the program it starts counting down from 1516960.
    How do I insert a new big_number

    I will be away from the computer for the next 2 hours.
    Thanks in advance for all the help.

    Nick

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


    Did you find this post helpful? Yes | No

    Default

    Yes, it loads 1 million into big_number.
    But it's a 32-bit binary number, so you can't just display the high/low WORDs with DEC.

    The hex representation of 1 million is F:4240.
    Then change each word to Decimal F=15, 4240=16960
    So it looks like it starts counting from 1516960

    To convert the big_number to a readable decimal output takes a little more work.

    Code:
    HighDigits  VAR WORD
    LowDigits   VAR WORD
    
    ;---[add this with the other macro's]---------------
    ASM
    PutMulResult?N  macro Nin
        MOVE?WW  Nin, R2
        MOVE?WW  Nin + 2, R0
      endm
    ENDASM
    
    
    ;---[add this to your main loop]--------------------
    @   PutMulResult?N  _big_number
        GOSUB SendBigNum
    ;---------------------------------------------------
    
    SendBigNum:
        HighDigits = DIV32 10000
        LowDigits  = R2
        IF (HighDigits > 0) THEN
            HSEROUT [DEC HighDigits, DEC4 LowDigits]
        ELSE
            HSEROUT [DEC LowDigits]
        ENDIF
    RETURN
    How do I insert a new big_number
    That depends on where the new big_number is coming from.

    You said you're reading the file length from the USB device.
    What format is it in, what variables are you storing it in.
    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