Page 1 of 1
I HATE DIV!!!
Posted: Wed Aug 08, 2001 12:03 pm
by Peter_Vigren
Scenario:
I tries to divide 1536 with 1024. The result should be that Ax will contain 1 and Dx 5. However, Dx contains 512 when I tested it. Then I divided 1792 with 1024 and got 1 in Ax and 768 in Dx...
It seems to me that the CPU (by some insane reason) multiply the remainder with 1024 because 0.5 multiplied with 1024 is 512 and 0.75 multiplied with 1024 is 768... Is this correct??
Now I wonder, HOW ON EARTH DO I DO TO DIVIDE 1536 AND GET 1 IN AX AND 5 IN DX???
Best regards,
Peter Vigren
Re: I HATE DIV!!!
Posted: Thu Aug 09, 2001 12:41 am
by df
Scenario:
I tries to divide 1536 with 1024. The result should be that Ax will contain 1 and Dx 5. However, Dx contains 512 when I tested it. Then I divided 1792 with 1024 and got 1 in Ax and 768 in Dx...
those numbers are fine!
mov eax,1536
mov ebx,1024
xor edx,edx
idiv ebx
eax = 1
edx = 512
which is correct.
edx wont be 5.. (1536-1024 does not have a remainder of 5) (1536/1024 = 1.5, but that is not how the computer does it, 512 being half of 1024.. hence the .5)
Re: I HATE DIV!!!
Posted: Thu Aug 09, 2001 5:33 am
by BLoggins02
Gotta love DIV and MUL ;D
Once you understand 'em, they're your best friends, but until then, be prepared to lose some hair! Hehe
Re: I HATE DIV!!!
Posted: Thu Aug 09, 2001 2:52 pm
by Peter_Vigren
those numbers are fine!
mov eax,1536
mov ebx,1024
xor edx,edx
idiv ebx
eax = 1
edx = 512
which is correct.
edx wont be 5.. (1536-1024 does not have a remainder of 5) (1536/1024 = 1.5, but that is not how the computer does it, 512 being half of 1024.. hence the ?.5)
Well then... How do I do to "translate" 512 (or 768) to 5 (or 75)?????? I need a program which rounds up bytes into Kb/Mb/Gb/Tb in the format a.bb or just a (if it is an even number)... Any tips??????
Best regards,
Peter Vigren
Re: I HATE DIV!!!
Posted: Thu Aug 09, 2001 11:20 pm
by VLAVI
...one idea:
you want : 1536/1025 = 1.5
1) to obtain the first number:
1536 div 1025 -> COCIENT 1 ( THE FIRST NUMBER!)
? ? ? ? ? ? ? ? ? ? ? ? REST = 512
2) next number (moving one place right in decimals <=> * 0.1)
REST / 1024 = COCIENT 5 (NEXT NUMBER!)
? ? ? ? ? ? ? ? ? ? ?REST = 0 -> STOP
? ? ? ? ? ? ? ? ? ? ?REST != 0 -> DO 2) until the number of decimals wanted)
In this example you have RESULT = 1 + (5*0.1) = 1.5
The divisor (1024) could be other...
Maybe this idea will help you...
...try other examples to adjust it...
Re: I HATE DIV!!!
Posted: Sat Aug 11, 2001 2:44 am
by VLAVI
SORRY! in step 2) I've forgotten something:
you have to multiply by 10 the previous rest, so:
(10 * REST) div 1024 -> cocient = 5
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rest = 0