在彙編減法中,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.