8086 assembly - divide overflow

江枫思渺然 提交于 2019-12-08 12:28:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!