There's no way to do that with DIV32. The Quotient must be less than 65535.
You would need a TRUE 32 bit divide routine.
Or you could use the Floating Point Math routines from melabs.
http://www.melabs.com/resources/fp.htm
Darrel
There's no way to do that with DIV32. The Quotient must be less than 65535.
You would need a TRUE 32 bit divide routine.
Or you could use the Floating Point Math routines from melabs.
http://www.melabs.com/resources/fp.htm
Darrel
hi darrel ,
do you have some example about the usage of floating point numbers.
after i do my multiplication and division how can i use aint variable?
i have to send the aint to my motor controller byte by byte.
thanks
Hi Darrel,
I like your ideas about getting at DIV32 system variables, but I have a slightly different situation. How do I use a variable for the divisor that wont violate the 15 bit rule?
I tried the following example, but it don't work (I get: Error Bad expression):
I really need the ability to alter the divisor via program control, and at times it will need to be bigger then an 8-Bit value. Any ideas?Code:divisor var word dummy var word dummy = DIV32 divisor
Thanks,
Edit: Opps! my mistake. It does work properly with a word variable as the divisor, just so long as you stay with the 15 bit rule (32767). This is good news.
Last edited by mytekcontrols; - 18th June 2005 at 01:24.
I just saw this link. it is of great interest to me right now...
I have this question... how do you add two of these Dwords?
how do i know if the add of two words overflows?
i.e. $1FFFE + $2E
my guess is to add the lower words $FFFE+$2E. But how do i know if there is an overflow? so that i can add one to the higher WORD? even worse..
i.e. $EFFF8 + $6FFE4
My guess again: add two lower words... if over flow add two higher words +1, else add two higher words....
I think i can manage myself once i am sure abour the overflow
Thanks,
For words and bytes, you can detect an overflow by testing if the result is less than what you added.
Due to trucation of a 16-bit word ...
$FF00 + $0180 = $0080
So the result will always be less than either of the values added if an overflow occurs.
I'm sure you could. But that's just not my way ...I think i can manage myself once i am sure abour the overflow
Which displays ...Code:;Initialize your hardware first A VAR WORD[2] B VAR WORD[2] Result VAR WORD[2] OVRFLOW32 VAR BIT ASM ; ===== Load 32bit Constant into DWORD ============================= MOVE?CD macro C32in, Dout ; Max= 4,294,967,296 MOVE?CB low C32in, Dout MOVE?CB low (C32in >> 8), Dout + 1 MOVE?CB low (C32in >> 16), Dout + 2 MOVE?CB low (C32in >> 24), Dout + 3 endm ENDASM @ MOVE?CD 0xEFFF8, _A ; Load 983,032 into A @ MOVE?CD 0x6FFE4, _B ; Load 458,724 into B GOSUB Add32 LCDOUT $FE,1, "A= ",HEX4 A[1],":",HEX4 A[0] LCDOUT $FE,$C0,"B= ",HEX4 B[1],":",HEX4 B[0] LCDOUT $FE,$90,"Res= ",HEX4 Result[1],":",HEX4 Result[0] LCDOUT $FE,$D0,"OVRFLOW32 = ", BIN1 OVRFLOW32 stop ; ===== Add 2 32bit variables ====================================== Add32: OVRFLOW32 = 0 Result[0] = A[0] + B[0] IF Result[0] < B[0] then Result[1] = 1 Result[1] = Result[1] + A[1] IF Result[1] < A[1] then OVRFLOW32 = 1 Result[1] = Result[1] + B[1] IF Result[1] < B[1] then OVRFLOW32 = 1 RETURNHTH,Code:A= 000E:FFF8 B= 0006:FFE4 Res= 0015:FFDC OVRFLOW32 = 0
DT
Checking for a smaller result is a simple trick, thanks,
right now my code is never suposed to exced the Max= 4,294,967,296
so i am ignoring the OVRFLOW32 = 0.
This is the code that i am using
Would this be ok? i made some tests and it seems ok but your experience might see anything wrong here.Code:Bigword var word [2] BigwordL var BigWord(0) BigwordH var BigWord(1) Bigword1 var word [2] Bigword1L var BigWord(0) Bigword1H var BigWord(1) AddTwoBigWords: 'Adds Bigword1 and BigWord2 result in BigWord BigWordH = BigWordH + BigWord1H ;ignoring any overflow BigWordL = BigWordL + BigWord1L if BigWordL < BigWord1L then BigWordH = BigWordH+1 ;ignoring any overflow endif return
Last edited by Josuetas; - 28th July 2007 at 16:03.
Bookmarks