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