Retrieving 32bit Multiply Result
Here's an example that I find rather useful from time to time.
You may have seen in the manual that when you multiply two 16bit numbers together, the result is a 32bit number that can then be used with the DIV32 command. But the 32bit multiply result is not available to the user, it's only in PBP system variables where you can't get at it.
This little routine let's you retrieve that 32 bit result.
Code:
A32bitVar var word[2]
Dummy var word
ASM
GetMulResult macro Dword
MOVE?WW R2, Dword ; Low Word
MOVE?WW R0, Dword + 2 ; High Word
endm
ENDASM
Dummy = 1000
Dummy = Dummy * Dummy
@ GetMulResult _A32bitVar
end
The 32 bit result for 1,000,000 is now contained in the two words of A32bitVar.
HTH,
Darrel Taylor
Any way to use a variable for DIV32 divisor?
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):
Code:
divisor var word
dummy var word
dummy = DIV32 divisor
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?
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.
Checking for a smaller result
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
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
Would this be ok? i made some tests and it seems ok but your experience might see anything wrong here.