When I use this code:
mov eax, smth
mov ebx, smth2
div bx
-it doesn't work, the program crashes. But when I use
div bl
the program doesn't crash, but the result is wrong. How can I solve this?
Posted on 2001-03-04 03:21:00 by IGosha
Hi, a small help: Operand Divident Quotient Rest ------------------------------------- Byte AX AL AH Word DX:AX AX DX DWord EDX:EAX EAX EDX Don't forget to save used register ! so long Test
Posted on 2001-03-04 05:09:00 by Test Department
sometimes, divs seems to crash because edx is not null, try with the following :
xor edx,edx
mov eax,whatever1
mov ebx,whatever2
div ebx
Posted on 2001-03-04 06:59:00 by roy
div bx -> divides dx:ax by bx div ebx -> divides edx:eax by ebx if you _know_ ax / eax is unsigned then you can simply "xor dx, dx" or "xor edx, edx" but with signed numbers you need to do a conversion first, this is very simply instruction "cwd" converts ax to dx:ax instruction "cdq" converts eax to edx:eax cwd = _C_onvert _W_ord to _D_ouble cdq = _C_onvert _D_ouble to _Q_uad so in your example the following should fix it ...

mov eax, smth
mov ebx, smth2
cdq
div ebx
cheers Clive [ Entro-P ]
Posted on 2001-03-04 09:08:00 by Entro-P