我正在尝试在emu8086中进行计算,但是似乎没有可用的根函数,我一直在尝试自己创建它,并且我想我已经知道了,但是我在两行中遇到了错误:
;si is the number that I need the square root of.
mov bx, 0 ;sets the cycle to start at 0
mov dx, si ;moves the number into dx for processing
sqrt: ;the loop, it continues as long as bx < si/2
mov ax, si ;from here starts this formula: x = (x + n / x) / 2
div dx ;I am getting a divide error -overflow here
add ax, dx
mov ch, 2
div ch ;the same divide error -overflow here
mov dx, ax
mov ax, si
mov ch, 2
div ch
cmp bx, ax ;the formula repeats until bx = si/2
jl sqrt
cmp bx, ax ; if bx = si/2, exit the loop.
jge cnt:
;sqrt si
cnt:
mov si, dx
为什么会显示两个错误?
中的16位除法运算8086
使用由寄存器内容形成的32位值DX:AX
作为除数,AX
并在中返回商,而在中返回余数DX
。如果商太大而无法容纳16位,则会INT 0
发生这种情况。
因此,当您执行以下操作时:
mov ax, si ;from here starts this formula: x = (x + n / x) / 2
div dx ;I am getting a divide error -overflow here
您将不是价值AX
的DX
,但价值DX:AX
的DX
。作为DX
与副本开始SI
,还有AX
呢,你分红SI*65536+SI
。
SI*65536+SI
除以SI
yields 65537
,该收益大于AX
可容纳的收益,因此产生除法误差。
关于这个:
mov ch, 2
div ch ;the same divide error -overflow here
8位除法AX
用作除数,返回中的商AL
和中的余数AH
。再一次,如果商太大AL
,则会发生溢出。在您的情况下,只要AX
其值等于或大于,就会发生溢出512
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句