书上看到的一句话:The CPU uses an interesting mechanism to determine
the state of the Overflow flag after an addition or subtraction operation. The Carry flag is exclusive ORed with the high bit of the result. The resulting value is placed in the Overflow flag.
就是说汇编里的OF寄存器里的值是CF和运算结果的最高位异或的结果。
书上的例子:
两个 8位 二进制数 10000000 and 11111110 相加
CF = 1 MSB = 0, 1 XOR 0 所以OF = 1.
1 0 0 0 0 0 0 0
+ 1 1 1 1 1 1 1 0
CF 1 0 1 1 1 1 1 1 0
结果和书上所说的一致。
但是如果对于8位 二进制数1111 1111和0000 0001
0 0 0 0 0 0 0 1
+ 1 1 1 1 1 1 1 1
CF 1 0 0 0 0 0 0 0 0
CF = 1 MSB = 0,1 XOR 0 所以OF = 1,但是如果这两个数是有符号数,分别为1和-1,它们相加OF必定为0!
那这句话有什么问题吗?还是我的例子有问题?
所以书上这句话是错的吧?
追答OF寄存器里的值是《CF和运算结果的最高位异或的结果。》
这句,不对。
最后一个问题:The Carry flag is exclusive ORed with the high bit of the result.The resulting value is placed in the Overflow flag.这句呢?是我的理解错了吗?这是书上的原话。
~谢谢
with the high bit of the result--这句,是说《结果的高位》。
但是,它说的,不对。
应该是:OF寄存器里的值,是CF和《次高位的进位》异或的结果。