汇编问题关于CF寄存器和OF寄存器书上看到的一句话:The CPU uses an interesting mechanism to determinethe state of the Overflow flag after an addition or subtraction operation. The Carry flag is exclusive ORed with the high bit of t
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/02 19:29:58
汇编问题关于CF寄存器和OF寄存器书上看到的一句话:The CPU uses an interesting mechanism to determinethe state of the Overflow flag after an addition or subtraction operation. The Carry flag is exclusive ORed with the high bit of t
汇编问题关于CF寄存器和OF寄存器
书上看到的一句话: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!
那这句话有什么问题吗?还是我的例子有问题?
汇编问题关于CF寄存器和OF寄存器书上看到的一句话:The CPU uses an interesting mechanism to determinethe state of the Overflow flag after an addition or subtraction operation. The Carry flag is exclusive ORed with the high bit of t
CF,是运算结果的《最高位》的进位.
运算结果的《次高位》,还有一个进位.
OF寄存器里的值,是CF和《次高位的进位》异或的结果.
即,相邻的两个进位,异或之后,就成了 OF.