Please explain me, why i get "Divide by zero" error for this code:
"mov ax,300
mov bl,2
idiv bl"
It should be as follows: al = ax div source, ah = ax mod source
Please explain me, why i get "Divide by zero" error for this code:
"mov ax,300
mov bl,2
idiv bl"
It should be as follows: al = ax div source, ah = ax mod source
idiv
is signed division which produces quotient inal
as you said. That is a 8 bit register and300/2=150
which does not fit into 8 bits when using signed arithmetic (since the maximum is127
). Somewhat misleadingly, you getdivide by zero
for overflow too (it's actually called#DE divide error
). This is of course written in the instruction set reference.You can use
div bl
if you are happy with an unsigned calculation, in that case150
fits intoal
and you won't get an error.