来自 DIV 个程序集的错误答案

Wrong answer from DIV assembly

我有一部分代码

mov di,3                                                           
mov cx,16
  looop:
  xor dx,dx
  shl bx,1
  adc dx,dx
  cmp cx,16
  je cx16 (it's will dec cx and jump loop)

  push dx
  dec cx
  cmp cx,0
  je  cx0
  mov ax,cx
  div di

cmp dx,0
jne looop

当 cx = 3
我会得到斧头 =3
但是div di
ax会变成H=55 L= 56
和 dx = 1
请问你能告诉我我做错了什么吗?

div di 将 32 位数量 dx:ax 除以 di。我们不知道您的 bx 有什么价值,但大概它会产生 dx=1(由于 adc dx, dx)。所以除法将是 0x10003 / 3 = 0x5556 余数 1,这正是你所看到的。

PS:学习使用调试器,适当阅读指令集参考