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
idivis signed division which produces quotient inalas you said. That is a 8 bit register and300/2=150which does not fit into 8 bits when using signed arithmetic (since the maximum is127). Somewhat misleadingly, you getdivide by zerofor overflow too (it's actually called#DE divide error). This is of course written in the instruction set reference.You can use
div blif you are happy with an unsigned calculation, in that case150fits intoaland you won't get an error.