News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

64 bit numbers with 32 bit asm

Started by someone, March 27, 2010, 06:53:32 AM

Previous topic - Next topic

donkey

Quote from: lingo on March 27, 2010, 02:15:26 PM
What do you think about MCoder's optimization here: http://www.asmcommunity.net/board/index.php?topic=5197.15

Nice, I have used the Svin's routine as a copy and paste for many years, probably since I first started in assembly, never saw any reason to change it or even look for a better solution as it worked and was more than enough for my purposes. Also there are exceedingly few times I ever need to convert qwords to ascii, I could probably count the number of times I needed one in the last 8 years on one hand...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

someone

ok thank you very much everybody the problems are solved now

special thanks to japeth, that was exactly the answer i was looking for, i didn't know about adc
here's my proc for those interested:

Add64Bit proc lpQwordOut:DWORD, dwInValueToAddHigh:DWORD, dwInValueToAddLow:DWORD
   mov ecx, lpQwordOut
   mov eax, dwInValueToAddLow
   mov edx, dwInValueToAddHigh
   add dword ptr [ecx], eax
   adc dword ptr [ecx+4], edx
   ret
Add64Bit endp

and also special thanks to donkey for the qw2a proc, that's also exactly what i was looking for, although
it's strange in the code that mm7 is preserved, anyway i'll remove that, and also avoid using bswap
to keep it with 386

also thanks to MichaelW for the floating point point example, it's so simple, i'm sure i have tried that in the past
but it never worked for me, i must have missed something, probably because in my debugger the fpu register
shows a decimal value and that threw me off

i guess the next stage would be 96 bit values, but thats for another day

also on a side note, i'm no beginner at assembly programming, it's been my main programming language for at
least 7 years now, i have just avoided dealing with these small things, until now

thanks again to everybody


Ghandi

Just wondering because i know nothing about this subject, when the ADC is performed would we then check to see that the total wasn't larger than 64 bits?

Example:

Num1 = F000000000000000
Num2 = 1000000000000000

Num1 + Num2 = 10000000000000000

Which is now a 72 bit number because it requires at least 9 bytes to store now, doesnt it? (68 bits if you allow nibbles instead of bytes)

HR,
Ghandi

someone

yes you are right, you can check
for my situation, i'm relying on not ever needing a number larger than 64 bits, so there isn't much need
but adc still sets the next carry flag if the number goes over 64 bits, i think means that the addition can
go on as many times as you want it to, by basically just repeating the last two lines

here are my procedures for those interested, now i have one that adds 96 bit numbers as well
also they check if the result is too big, and if it is then it sets the result to the maximum FFFF...

Add64Bit proc lp64BitNumber:DWORD, dwAddValueHigh:DWORD, dwAddValueLow:DWORD
   mov ecx, lp64BitNumber
   mov eax, dwAddValueLow
   add dword ptr [ecx], eax
   mov eax, dwAddValueHigh
   adc dword ptr [ecx+4], eax
   jc @too_big
   ret
@too_big:      ;will jump here, if the result is bigger than a 64 bit number
   mov dword ptr [ecx], 0FFFFFFFFh
   mov dword ptr [ecx+4], 0FFFFFFFFh
   ret
Add64Bit endp

Add96Bit proc lp96BitNumber:DWORD, dwAddValueHighest:DWORD, dwAddValueHigh:DWORD, dwAddValueLow:DWORD
   mov ecx, lp96BitNumber
   mov eax, dwAddValueLow
   add dword ptr [ecx], eax
   mov eax, dwAddValueHigh
   adc dword ptr [ecx+4], eax
   mov eax, dwAddValueHighest
   adc dword ptr [ecx+8], eax
   jc @too_big
   ret
@too_big:      ;will jump here, if the result is bigger than a 64 bit number
   mov dword ptr [ecx], 0FFFFFFFFh
   mov dword ptr [ecx+4], 0FFFFFFFFh
   mov dword ptr [ecx+8], 0FFFFFFFFh
   ret
Add96Bit endp

donkey

Quote from: lingo on March 27, 2010, 02:15:26 PM
"I usually use The Svin's qword to ascii routine"

Really? :wink
Would you be so kind to explain the meaning of the register mm7 and the local variable qstore?

Actually, going through some old old old code I found that it was me who added the preservation of mm7 because I needed it once and modified the function. After that I must have C&P'ed it from that program and it was viral at that point. So I can't blame that one on the Svin, it was my fault.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

raymond

someone,

Just in case you may want to learn a bit more, the latest version of the Fpulib contains two functions to convert qwords to ascii, one for unsigned and the other for signed qwords. Both are based on using multiplications instead of division to perform the conversion.

That latest version of the Fpulib also accepts qwords as input for many of the functions using the FPU.

AND, the source code of each function is included for your education in the downloadable file from:
http://www.ray.masmcode.com/fpu.html#fpulib

PLUS, if you ever want to learn how to program the FPU yourself, a tutorial explaining almost every aspect of using floats is available on the same page of the above link. You can browse it online or download the entire tutorial. Be sure to read and understand the first two chapters.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com