mov eax, 0
mov ebx, 0
mov edx, 0
mov ax, 31
mul cx
mov bx, 12
div bx
add bp, ax
mov eax, 0
mov ebx, 0
mov bp, bp
mov al, 7
div al
can anyone tell me whats wrong with the div al instruction in this block of code, so as I'm debugging every number of bp i calculated, when i divide by al it give me 1 as the remainder, why is this happen?
the remainder should be store back to ah register
thank in advance
edited code :
mov eax, 0
mov ebx, 0
mov edx, 0
mov ax, 31
mul cx
mov bx, 12
div bx
add bp, ax
mov eax, 0
mov ebx, 0
mov ax, bp
mov bl, 7
div bl
mov al, 0
You can't use al
as divisor, because the command div
assumes ax
to be the dividend.
This is an example for dividing bp
by 7
mov ax,bp // ax is the dividend
mov bl,7 // prepare divisor
div bl // divide ax by bl
This is 8 bit division, so yes the remainder will be stored in ah
. The result is in al
.
To clarify: If you write to al
you partially overwrite ax
!
|31..16|15-8|7-0|
|AH.|AL.|
|AX.....|
|EAX............|
edited code:
mov eax, 0
mov ebx, 0
mov ax, 31
mul cx
mov bx, 12
div bx
add bp, ax
mov eax, 0
mov ebx, 0
mov edx, 0
mov ax, bp
mov bx, 7
div bx
mov esi, edx
mov eax, 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With