问题
I try to make a simple division in assembly but I get "Divide overflow" error.
My simple code: cs:sum and cs:num is a byte variable. (db)
mov ax, word ptr cs:sum
mov cl, 10
xor dx,dx
div cl ; divide by 10
mov cs:num, ah ; ger rightest
Not sure why - but as I say - I fail to devide properly.
So do you know what is that problem and how to solve it? thanks !
(I'm using cs deference because that's a TSR program)
回答1:
For this to cause a division exception
mov ax, word ptr cs:sum
mov cl, 10
div cl
the value in ax
(coming from word ptr cs:sum
) must be >= 2560.
Either word ptr cs:sum
isn't < 2560 or addressing is broken in your code and you're not storing the value in word ptr cs:sum
or fetching it from there (e.g. you're not using the same segment value when referring to sum
).
Those are the only possibilities.
来源:https://stackoverflow.com/questions/12149560/8086-assembly-divide-overflow