Difference between revisions of "Overflow Flag"
(→Overflow's complicated!) |
m (Protected "Overflow Flag" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | 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 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—signed integer overflow. 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: | The truth table below indicates when the CPU sets or clears the Overflow Flag: | ||
<center> | <center> | ||
<table border=1> | <table border=1> | ||
| − | <tr><th COLSPAN= | + | <tr><th COLSPAN=5>Addition</TH></tr> |
| − | <tr><th>Sign of first operand</th><th>Sign of second operand</th><th>Sign of result</th><th>Resulting value of Overflow Flag</th></tr> | + | <tr><th>Sign of first operand</th><th>Sign of second operand</th><th>Sign of result</th><th>Resulting value of Overflow Flag</th><th>Notes</th></tr> |
<tr><td>0</td><td>0</td><td>0</td><td>0</td></tr> | <tr><td>0</td><td>0</td><td>0</td><td>0</td></tr> | ||
| − | <tr><td>0</td><td>0</td><td>1</td><td>1</td></tr> | + | <tr><td>0</td><td>0</td><td>1</td><td>1</td><td>Adding two positive numbers produced a negative result</td></tr> |
<tr><td>0</td><td>1</td><td>0</td><td>0</td></tr> | <tr><td>0</td><td>1</td><td>0</td><td>0</td></tr> | ||
<tr><td>0</td><td>1</td><td>1</td><td>0</td></tr> | <tr><td>0</td><td>1</td><td>1</td><td>0</td></tr> | ||
<tr><td>1</td><td>0</td><td>0</td><td>0</td></tr> | <tr><td>1</td><td>0</td><td>0</td><td>0</td></tr> | ||
<tr><td>1</td><td>0</td><td>1</td><td>0</td></tr> | <tr><td>1</td><td>0</td><td>1</td><td>0</td></tr> | ||
| − | <tr><td>1</td><td>1</td><td>0</td><td>1</td></tr> | + | <tr><td>1</td><td>1</td><td>0</td><td>1</td><td>Adding two negative numbers produced a positive result</td></tr> |
<tr><td>1</td><td>1</td><td>1</td><td>0</td></tr> | <tr><td>1</td><td>1</td><td>1</td><td>0</td></tr> | ||
| − | <tr><th COLSPAN= | + | <tr><th COLSPAN=5>Subtraction</TH></tr> |
| − | <tr><th>Sign of value being subtracted (subtrahend)</th><th>Sign of value being subtracted from (minuend)</th><th>Sign of result</th><th>Resulting value of Overflow Flag</th></tr> | + | <tr><th>Sign of value<br/>being subtracted<br/>(subtrahend)</th><th>Sign of value<br/>being subtracted from<br/>(minuend)</th><th>Sign of result</th><th>Resulting value of Overflow Flag</th></tr> |
<tr><td>0</td><td>0</td><td>0</td><td>0</td></tr> | <tr><td>0</td><td>0</td><td>0</td><td>0</td></tr> | ||
<tr><td>0</td><td>0</td><td>1</td><td>0</td></tr> | <tr><td>0</td><td>0</td><td>1</td><td>0</td></tr> | ||
| − | <tr><td>0</td><td>1</td><td>0</td><td>1</td></tr> | + | <tr><td>0</td><td>1</td><td>0</td><td>1</td><td>Subtracting a positive number from a negative number gave a positive result.</td></tr> |
<tr><td>0</td><td>1</td><td>1</td><td>0</td></tr> | <tr><td>0</td><td>1</td><td>1</td><td>0</td></tr> | ||
<tr><td>1</td><td>0</td><td>0</td><td>0</td></tr> | <tr><td>1</td><td>0</td><td>0</td><td>0</td></tr> | ||
| − | <tr><td>1</td><td>0</td><td>1</td><td>1</td></tr> | + | <tr><td>1</td><td>0</td><td>1</td><td>1</td><td>Subtracting a negative number from a positive number gave a negative result.</td></tr> |
<tr><td>1</td><td>1</td><td>0</td><td>0</td></tr> | <tr><td>1</td><td>1</td><td>0</td><td>0</td></tr> | ||
<tr><td>1</td><td>1</td><td>1</td><td>0</td></tr> | <tr><td>1</td><td>1</td><td>1</td><td>0</td></tr> | ||
</table></center> | </table></center> | ||
Latest revision as of 09:01, 4 December 2010
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—signed integer overflow. 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 | Notes |
| 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | Adding two positive numbers produced a negative result |
| 0 | 1 | 0 | 0 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | Adding two negative numbers produced a positive result |
| 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 | Subtracting a positive number from a negative number gave a positive result. |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 0 | |
| 1 | 0 | 1 | 1 | Subtracting a negative number from a positive number gave a negative result. |
| 1 | 1 | 0 | 0 | |
| 1 | 1 | 1 | 0 | |