How can i divide two 64-bits integers?

(if anyone have a bunch of macros or procs to simplify the task of working with 64-bits numbers, please send me a copy)

Posted on 2001-09-17 10:51:18 by Delight
Ok heres the deal, havent checked this, but it should work:
(surprised it took 45 odd readings and still no responce)

ah32 dd ? ; upper 63-32 bits of numerator
al32 dd ? ; lower 31-0 bits

bh32 dd ? ; upper 63-32 of denominator
bl32 dd ? ; lower 31-0

Quotient dd ?


xor ecx, ecx
mov eax, ah32

.if( eax == bh32 )
mov eax, al32
.if( eax < bl32 )
jmp @F
.elseif (eax < bh32 )
jmp @f

mov eax, al32
mov edx, bl32
sub eax, edx
mov al32, eax

mov eax, ah32
mov edx, bh32
sbb eax, edx
mov ah32, eax

inc ecx
jmp @B
mov Quotient, ecx

The remainder is now in ..

Hope this helps, there is no faster way than itteration when you have 64 bits, PLUS, the extra confusion of a 64 bit denominator.

Hope this helps..
Posted on 2001-09-18 01:39:16 by NaN
Hello !

You can do this divide with the fpu:

fild qword ptr [Val1]
fild qword ptr [Val2]
fdivrp st(1), st
fistp qword ptr [Val3]

In Val3 (as 64 Bit) will be stored the result of the division of Val1 by Val2 (both as 64 bit-integers loaded)

Greetings, CALEB
Posted on 2001-09-18 02:12:37 by Caleb
Doh! Doh! DOh! :)

I should really practice more floating point, i forgot all about the QWORD... ((( DOH! )))

Posted on 2001-09-18 02:20:22 by NaN
Thanks guys!

I must admit that Nan's version looks a little complicated compared to Calebs, but don't worry, I'll try your code too Nan... :rolleyes:


Posted on 2001-09-18 02:49:21 by Delight