如何在emu8086中绘制平方根

阿诺德

我正在尝试在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

为什么会显示两个错误?

mcleod_ideafix

中的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

您将不是价值AXDX,但价值DX:AXDX作为DX与副本开始SI,还有AX呢,你分红SI*65536+SI

SI*65536+SI除以SIyields 65537,该收益大于AX可容纳收益因此产生除法误差。

关于这个:

mov ch, 2
div ch      ;the same divide error -overflow here

8位除法AX用作除数,返回中的商AL和中的余数AH再一次,如果商太大AL,则会发生溢出。在您的情况下,只要AX其值等于或大于,就会发生溢出512

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章