在汇编减法中,CF=INVERT(carry out of the MSB),原因如下。
考虑减法运算的实际过程。对于A - B操作,有
其中M = MAX + 1。(比如,若A为int类型,则MAX = 32767, M = 32768)
那么,便可以分情况讨论:
1. 则A - B + M >= M,A >= B,即被减数大于等于减数。此时CF = INVERT(1) = 0
2. 否则CF = 0,A - B + M < M,即被减数小于减数。此时CF = INVERT(0) = 1
通过总结,我们发现,CF = 0对应被减数大于等于减数(无借位);CF = 1对应被减数小于减数(有借位)。这说明,对于ADD,CF表示进位;而对于SUB,CF表示借位。
同时,这也解释了对于NEG指令,Any nonzero operand causes the Carry flag to be set。
而对于汇编乘法中的CF位,The Carry flag indicates whether or not the upper half of the product contains significant digits.