5

我正在使用 MASM32。

使用此代码:

mov eax,5
sub eax,10

CF 状态标志将被设置。但是使用我的铅笔和纸,我实际上看到 MSB 没有任何进位。是的,我知道从少数大数集 CF 中减法。但我想知道为什么?

因为使用此代码:

mov eax,5
mov ebx,10
not ebx
add ebx,1
add eax,ebx

永远不会设置 CF 标志。

4

2 回答 2

5
5 - 10 = 5 + (-10) = 0x05 + (0xF5 + 1) = 0x05 + 0xF6 = 0xFB

  00000101 -- 0x05
  11110101 -- 0xF5
+ 00000001 -- 0x01
==========
  11111011 -- 0xFB

And this continues for 16 or 32 or 64 bits 0+1+0 = 1, carry 0

You are right in the sense that it doesnt carry out. A subtract is an add with the second operand inverted and the carry in inverted. Some processor families invert the carry out some dont. Sounds like you are looking at something that inverts the carry out on a subtract.

So if 5 - 10 gives carry out (borrow) then try 10 - 5 on the same processor, you should not see the carry bit set (no borrow).

Your second example is an add operation, the carry out is not inverted on any processor that I know of, further supporting the carry bit being positive logic indicating a borrow.

于 2012-09-02T17:06:38.923 回答
1

在第一种情况下,设置进位标志是因为您从较小的数字中减去了较大的数字。在第二种情况下,假设 eax 是 8 位寄存器然后

    eax=00000101=05
    ebx=00010000=10
not ebx=11101111
         +     1
---------------------
        11110000
         +  0101
 ---------------------
        11110101

没有发生溢出,即没有设置进位标志。

于 2012-09-02T17:09:30.947 回答