N-Bit_MATH


Closed Thread
Results 1 to 39 of 39

Thread: N-Bit_MATH

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    You didn't miss anything.
    I fixed it within 50 minutes from your report, and reposted before you could say MOVE?PP.

    Gets lost in the back and forth
    I'm glad it's working better for you now.
    <br>
    DT

  2. #2
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default N-Bit Division Numbskull Here

    Greeting All.

    This is my first post, but I've been lurkin' and learnin' from this site for quite a long time. Thanks to all the regulars for your great threads. I'm an aerodynamicist by training, but like to to tinker with just about everything geeky.

    I can muddle my way through BASIC, but have quite a bit of difficulty with assembler, though by necessity, I am beginning to learn a little.

    I was very excited by the N-Bit Math routines, since it should allow high precision to be carried through all the computations. I am especially interested in the MATH_DIV w/ Remainder routine. I've had a problem with some of my projects where I need to divide two large numbers, yet retain the precision.
    I was hopeful that the N_BIT Math will allow that.

    I've spent many hours now trying to implement this in my chip, but have been unable to get meaningful output.

    I developed this simple test program to try to understand it (unsuccessfully):

    Code:
    ' TROUBLESHOOTER for N-BIT MATH
    ' By WOZZY
    ' PIC18F4680
    ' Compile with -n -ampasmwin Build Options
    ' 32 BIT LONG
    
    
    INCLUDE "N-Bit_Math.pbp"	' Include Alexander Avtanski's Multibyte Arithmetic 
    				' Assembly Library Wrapped for PBP by Darryl Taylor
    				' Version:1.3 Beta (1/7/2010)
    
    DEFINE OSC 20			' 20 MHz Crystal Oscillator
    
    DEFINE DEBUG_REG PORTC		' PORT C6
    DEFINE DEBUG_BIT 6 			' PORT C6
    DEFINE DEBUG_BAUD 57600		' BAUD 57600
    DEFINE DEBUG_MODE 0 		' 1 = inverted, 0 = true
    
    PRECISION CON 8 SYSTEM  	' 8 bytes = 64-bit
    
    I			VAR	BYTE
    
    AA_LONG	VAR LONG  
    BB_LONG	VAR LONG 
    CC_LONG    VAR LONG
    DD_LONG    VAR LONG
    
    AA64 		VAR BYTE[PRECISION]
    BB64		VAR BYTE[PRECISION]
    CC64     	VAR BYTE[PRECISION]
    DD64		VAR BYTE[PRECISION]
    
    XX64		VAR BYTE[PRECISION]
    YY64		VAR BYTE[PRECISION]
    ZZ64		VAR BYTE[PRECISION]
    
    PAUSE 500 : DEBUG "   ",10,13,10,13 : PAUSE 500
    
    MAIN:
    
    	AA_LONG	= 2134567891
    	BB_LONG	= 1987654321
    	CC_LONG = 2176437299
    	DD_LONG = 12
    	
    	@  MOVE?LP  _AA_LONG, _AA64		; @  MOVE?LP  _Lin, _Pout   ; copy a LONG to a Pvar (PBPL only)
    	@  MOVE?LP  _BB_LONG, _BB64		; @  MOVE?LP  _Lin, _Pout   ; copy a LONG to a Pvar (PBPL only)
    	@  MOVE?LP  _CC_LONG, _CC64		; @  MOVE?LP  _Lin, _Pout   ; copy a LONG to a Pvar (PBPL only)
    	@  MOVE?LP  _DD_LONG, _DD64		; @  MOVE?LP  _Lin, _Pout   ; copy a LONG to a Pvar (PBPL only)
    	@  MATH_MUL  _AA64, _BB64, _XX64	; @  MATH_MUL  _A, _B, _Res ; Res = A / B - Remainder in REG_Z
    	@  MATH_DIV  _CC64, _DD64, _YY64	; @  MATH_DIV  _A, _B, _Res ; Res = A / B - Remainder in REG_Z
    	@  MATH_DIV  _DD64, _CC64, _ZZ64	; @  MATH_DIV  _A, _B, _Res ; Res = A / B - Remainder in REG_Z
    	
    	DEBUG "BYTE ORDER BYTE[7],BYTE[6],BYTE[5],BYTE[4],BYTE[3],BYTE[2],BYTE[1],BYTE[0]",10,13,10,13
    	DEBUG "AA64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 AA64[I] : NEXT I : DEBUG 10,13
    	DEBUG "BB64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 BB64[I] : NEXT I : DEBUG 10,13
    	DEBUG "CC64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 CC64[I] : NEXT I : DEBUG 10,13
    	DEBUG "DD64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 DD64[I] : NEXT I : DEBUG 10,13
    	DEBUG "XX64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 XX64[I] : NEXT I : DEBUG 10,13
    	DEBUG "YY64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 YY64[I] : NEXT I : DEBUG 10,13
    	DEBUG "ZZ64 = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 ZZ64[I] : NEXT I : DEBUG 10,13
    	DEBUG "REG_Z = " : FOR I = 7 to 0 Step -1 : DEBUG BIN8 REG_Z[I] : NEXT I : DEBUG 10,13
    	DEBUG 10,13,10,13,10,13,10,13
    	PAUSE 10000
    GOTO MAIN
    
    END
    Here is the commented output:

    Code:
    BYTE ORDER BYTE[7],BYTE[6],BYTE[5],BYTE[4],BYTE[3],BYTE[2],BYTE[1],BYTE[0]
      
    AA64 = 0000000000000000000000000000000001111111001110101110101111010011
         = 12   OK, Should Be 2134567891:  (MOVE?LP)
    
    BB64 = 0000000000000000000000000000000001110110011110010011001010110001
         =  1987654321   OK, Should Be: 1987654321   (MOVE?LP)
    
    CC64 = 0000000000000000000000000000000010000001101110011100110000110011
         = 2176437299   OK, Should Be: 2176437299   (MOVE?LP)
    
    DD64 = 0000000000000000000000000000000000000000000000000000000000001100
         =12   OK, Should Be 12:   (MOVE?LP)
    
    XX64 = 0111010100000000000000000100110000000000000000000000000000000000
         = 8,430,738,828,855,080,000   Should Be: 4,242,783,092,014,010,000 (MATH-MUL)
    
    YY64 = 0000000001000000000000000000000000000000000000000000000000000000
         = 18,014,398,509,482,000   Should Be: 181,369,774  (MATH_DIV)
    
    ZZ64 = 0000000001001100000000000000000000000000000000000000000000000000
         = 21,392,098,230,009,900   Should Be: 0  (MATH_DIV)
    
    REG_Z = 0000000000000000010011000000000000000000000000000000000000000000
          = 83,562,883,710,976   Should Be: 0.0000000055135978  (Remainder)
    So I was wondering if anyone has successfully implemented the Multiplication and Division in N_BIT Math.

    I would really appreciate it if someone could help me decode the output, point out the error in my ways, or at least point me in the right direction.

    Thanks,
    Wozzy-2010

    PS. Darryl, A huge thank you for all the routines you have developed.
    Your Inst_Interrupts are better than sardines on toast.
    Wozzy-2010

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


    Did you find this post helpful? Yes | No

    Default

    Ewwww, that's ugly.
    And I agree, something's not right.

    I will see what I can find.
    Thanks Wozzy,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Whew, had me worried there for a minute.

    In order for the Include file to create the correct size working variables ...
    The PRECISION constant needs to be BEFORE the include file.

    Code:
    PRECISION CON 8 SYSTEM  	' 8 bytes = 64-bit
    INCLUDE "N-Bit_Math.pbp"	' Include Alexander Avtanski's Multibyte Arithmetic 
    				' Assembly Library Wrapped for PBP by Darryl Taylor
    				' Version:1.3 Beta (1/7/2010)
    It was creating Working vars of only 1 byte, instead of 8 bytes.
    After moving the constant, I got all the correct results with your program.

    HTH,
    DT

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Hmm, Darrel, don't you ever sleep?

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Hmm, Darrel, don't you ever sleep?
    Yeah, but it's hard to get the drool out of the keyboard ...
    Not to mention deleting several hours worth of J's where my nose pressed, so I try to avoid it.
    <br>
    DT

  7. #7
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel

    Ouch....My head is sore from banging it on the workbench.

    I'll try this out tonight and let you know.

    I knew it must be something simple I was missing.

    Wozzy
    Wozzy-2010

Members who have read this thread : 1

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