Overflow Flag
The Overflow Flag indicates that the previous operation resulted in a signed number whose sign was inconsistent with the signs of the operands that produced it. For instance, the Overflow Flag gets set when adding two positive numbers produces a negative result, or adding two negative numbers produces a positive result.
The truth table below indicates when the CPU sets or clears the Overflow Flag:
Addition | |||
---|---|---|---|
Sign of first operand | Sign of second operand | Sign of result | Resulting value of Overflow Flag |
0 | 0 | 0 | 0 |
0 | 0 | 1 | 1 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 0 |
Subtraction | |||
Sign of value being subtracted (subtrahend) | Sign of value being subtracted from (minuend) | Sign of result | Resulting value of Overflow Flag |
0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 1 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 0 |
1 | 1 | 1 | 0 |