News:

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

64bit division

Started by Pincopall, November 10, 2006, 06:01:25 PM

Previous topic - Next topic

Pincopall

Hi,
I'm programming in masm and
here's my problem: I've to divide by 10 an hex number 9 of nine chars.
The first char of this number is in edx and the others 8 are in eax.
How can I make my program understand that the number is in a qword?
If I do a "div ecx" ( ecx = 0000000Ah) and edx is not 0 then the program crashes, if I do "cdq - idiv ecx" , the cdq  put 00 in edx, and this is not good!
I've seen that MulDiv multiplies two 32-bit values and then divides the 64-bit result by a third 32-bit value and I've seen that to divide the 64 bit number it simply does a "div ecx"  and it works because the division follows immediatly a multiplication, if you do for istance a "xor" on the number that you've obtained from the multiplication the "div ecx" crashes. So I can't do the same.
What can I do?
Thanx and byebye

ToutEnMasm


Hello,
There is a crash when edx isn't null just after the division and there is a remainder.
Edx couldn't be the quotient and the remainder.
Try the FPU or or an algebric formula to solve this.
                             ToutEnMasm

dsouza123

The issue is if edx >= ecx then the result is bigger than a dword, which causes an exception.
so edx has to be the new number which is divided by ecx
the quotient eax is the upper dword of the result,
the remainder stays in edx and eax gets the lower dword of the original number
again divide by ecx
eax is the lower dword of the quotient, edx is the remainder

0D 0000 0000h / 0Ah  --> 01 4CCC CCCCh, 8   quotient, remainder

0Dh / 0Ah -->  1, 3  use first (eax) 1 as upper dword of quotient, use second (edx) 3 as new upper dword of numerator
03 0000 0000h / 0Ah --> 4CCC CCCCh, 8
01 4CCC CCCCh is the quotient, and 8 is the remainder

[attachment deleted by admin]