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

    Only works for me with MPASM assembler case sensitive option enabled.
    Well, then keep case sensitivity enabled.

    OK, since it's you bruce.
    Update 1.2 Alpha ; adds ability to turn Case Sensitivity off in MPASM
    Changes SAVEFSR and RESTFSR, to FSRSAVE and FSRREST.

    http://www.picbasic.co.uk/forum/atta...4&d=1262930635

    I think I'll go MOVE?PP now.
    <br>
    DT

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Must have missed a version update somewhere in the mix. 1.2a works as expected.

    Nice find on the math routines. Very handy. Nice work on the PBP wrappers too.

    Thanks.

    What I had tested was the 1.1 Alpha 1/4/2010 ; fixes FSR conflict with DT_INTS-18
    in post #1, which changed to 1.2 alpha within just few minutes from posting.
    Last edited by Bruce; - 5th January 2010 at 00:33.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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

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

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

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

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default

    Hmm, Darrel, don't you ever sleep?

    Ioannis

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