【发布时间】:2014-01-01 00:54:04
【问题描述】:
我正在尝试在 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
为什么会出现这两个错误?
【问题讨论】:
-
您必须确保当您放置新的划分数字时,目标容器在您的案例
dx和ch可以容纳 div 返回的位数。 stackoverflow.com/questions/13941631/… -
emu8086 不支持 FPU?如果 emu8086 支持 FPU,FSQRT 会做你想做的事。