I have problem, this code works fine. Multiply 10 x 2. Result, i get 20 in messagebox.

.data?
buffer dd ?

.code

start:
mov eax,10
mov ecx,2
mul ecx
invoke dwtoa, eax, addr buffer
invoke MessageBox,NULL,addr buffer,NULL,MB_OK
invoke ExitProcess, NULL
end start
I thought div & mul works the same way. I try this code and i get fatal program.

.data?
buffer dd ?

.code

start:
mov eax,10
mov ecx,2
div ecx
invoke dwtoa, eax, addr buffer
invoke MessageBox,NULL,addr buffer,NULL,MB_OK
invoke ExitProcess, NULL
end start
Can someone show me right of way? Also, how can i div & mul, with fractions and decimals??? Any tutorial???
Posted on 2001-05-03 11:47:00 by Boris
If you look at the opcodes.hlp file at the div instruction, it states the following:
F6 /6 DIV r/m8 Unsigned divide AX by r/m8 F7 /6 DIV r/m16 Unsigned divide DX:AX by r/m16; AX F7 /6 DIV r/m32 Unsigned divide EDX:EAX by r/m32 doubleword
So "div ecx" is infact a division of the 64bit value, where edx represents the top 32bits of the value, and eax is the bottom 32bits. Your program will crash when the value the whole 64bit value when divided is greater than 32bits. As you haven't assigned edx a value in this example it will have some random and unpredictable value. As you are only dividing by 2, the only values that will succeed will be if edx = 0 or 1. Add the line "xor edx, edx" somewhere before the div. Or alternatively change the div to "div cl" then add the line "and eax, 0FFh". This is because when div-ing by an 8bit value, the remainder is left in AH, and the quotient is in AL (and we only want the quotient). Hope that clears things up for you Mirno
Posted on 2001-05-03 12:24:00 by Mirno
I am seeing now! Thank you Mirno :)
Posted on 2001-05-03 15:06:00 by Boris