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 in al
as you said. That is a 8 bit register and 300/2=150
which does not fit into 8 bits when using signed arithmetic (since the maximum is 127
). Somewhat misleadingly, you get divide 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 case 150
fits into al
and you won't get an error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.