携带标志问题!
假设 AX =FFFE 且 BX=1234
现在如果我们写 cmp ax,bx
(bx将从ax中减去,并且适当的标志将被更新) 现在 ax 和 bx 中数字的二进制表示由
AX = 1111 1111 1111 1110
BX= 0001 0010 0011 0100
给出 由于 bx 将从 ax 中减去,因此我们必须对 bx 取负(结果 = ax+(-bx)) 所以求反的 bx (bx 的 2 补码)由下式给出。
BX= 1110 1101 1100 1100
现在我们将 ax 和 bx 相加(因为减法是通过计算机中的加法实现的)
AX= 1111 1111 1111 1110
BX= 1110 1101 1100 1100
------------------------------------
1 1110 1101 1100 1010
现在你可以看到结果是 17现在第17位应该进入进位标志,但是当我检查它时,进位标志是0,即CF=0,为什么?
Suppose AX =FFFE and BX=1234
now if we write cmp ax,bx
(bx will be subtracted from ax and the approprite flages will be updated)
now the binary representation of the numbers in ax and bx is given by
AX = 1111 1111 1111 1110
BX= 0001 0010 0011 0100
As bx will be subtracted from ax so we have to negate bx (as Result= ax+(-bx))
so the negated bx (2's complement of bx ) is given by.
BX= 1110 1101 1100 1100
Now we add both ax and bx (as subtraction is implemented by addition in computer)
AX= 1111 1111 1111 1110
BX= 1110 1101 1100 1100
------------------------------------
1 1110 1101 1100 1010
Now as you can see the result is of 17 bits now the 17th bit should go into carry flage, but when i checked it the carry flag is 0 that is CF=0 why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里找到了一个链接:
http://oopweb.com/Assembly/Documents/ArtOfAssembly/ Volume/Chapter_6/CH06-2.html
正如我所料。仅当需要“借位”时才设置进位标志。进行减法时,您在进行“减法”之前设置进位标志,新的进位标志会告诉您是否必须借位。您的示例省略了在位 17 中为预设进位标志添加 1,这将导致结果中没有进位。
Found a link here:
http://oopweb.com/Assembly/Documents/ArtOfAssembly/Volume/Chapter_6/CH06-2.html
It is as I expected. The carry flag is set only if "borrow" was required. When doing subtraction, you set the carry flag prior to doing the "subtract" and the new carry flag tells if you had to borrow. Your example omitted the addition of 1 for the pre-set carry flag in bit 17 which will cause no carry in the result.
执行减法时,将进位标志视为借位位。它初始化为 1,因此运算为
a−b−C
,即a + not(b) + C
而不是a + not(b) + 1
正如您所描述的。换句话说,进位被反转以进行减法,因此可以用于进行多精度减法。Think of the carry flag as a borrow bit when subtraction is performed. It is initialized to 1 so the operation is
a−b−C
, i.e.,a + not(b) + C
instead ofa + not(b) + 1
as you described. In other words, the carry is inverted for subtract so it can be used to do multiple-precision subtract.