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
I HATE DIV!!!
Re: I HATE DIV!!!
those numbers are fine!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...
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)
-- Stu --
Re: I HATE DIV!!!
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
Once you understand 'em, they're your best friends, but until then, be prepared to lose some hair! Hehe
Re: I HATE DIV!!!
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??????
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)
Best regards,
Peter Vigren
Re: I HATE DIV!!!
...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...
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!!!
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
you have to multiply by 10 the previous rest, so:
(10 * REST) div 1024 -> cocient = 5
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rest = 0