Well i am really proud of this, i Hope its ok.
For anyone in need of a Division of a BigWord by some number i found this problem:
Lets think of a BigWord as considered before ^
Now you might want to Divide a value stored in tBigWord1 by some other value, in this case (EXAMPLE CODE) the value is stored in factoriva.
One could use the DIV32 function as proposed by Darrel in this or other post BUT if factoriva is too small the result CAN be higher than a word size FFFF, and the the result is no good.
For example:
4:01F5 DIV32 2 the result of DIV32 is
Result = FFFF, Remainder = 01F7 !! Wrong i guess
This code is possible just thanks to Darrel`s @ PutMulResult?D MACRO
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)
MainLoop:
lcdout $fe,1
tbigword1H = 4 ' My Dollars Value High Word
tbigword1L = 501 ' My Dollars value Low Word
cents = 24 ' My cents value
GOSUB DIVBIGWORD
HSEROUT [#FactorIva," ",HEX4 tBigWordH,":", HEX4 tBigWordHL,10,13]
FactorIva= FactorIva+ 1
IF FactorIva= 101 THEN
END
ENDIF
GOTO MainLoop
'This SUB receives tBigWord1(Dword) a value to be divided by
'FactorIva (word), Result in tBigWord, works for any value of FactorIva
'and tBigWord1 in their limits.
DIVBigWord:
tBigWordH= tBigWord1H / FactorIva
tBigWord1H = tBigWord1H // FactorIva
@ PutMulResult?D _tBigWord1
tBigWordL = DIV32 FactorIva
Remainder = R2
RETURN
This code in the serial port os The value tBigWord1 Divided for Factors 1 to 100
Seems to work.
Factor Result
2 0002:00FA
Remember to Add the @ PutMulResult?D MACRO posted by Darrel at the begining of the Code.
Bookmarks