Difference between revisions of "Overflow Flag"

From Intellivision Wiki
Jump to: navigation, search
 
(Overflow's complicated!)
Line 1: Line 1:
The Overflow Flag indicates that the previous operation resulted in a signed number that was too large or too small to be contained in a single register.
+
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:
 +
<center>
 +
<table border=1>
 +
<tr><th COLSPAN=4>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><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>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>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>1</td><td>0</td><td>1</td></tr>
 +
<tr><td>1</td><td>1</td><td>1</td><td>0</td></tr>
 +
<tr><th COLSPAN=4>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><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>1</td><td>0</td><td>1</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>1</td><td>1</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>
 +
</table></center>

Revision as of 00:36, 12 January 2005

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 operandSign of second operandSign of resultResulting value of Overflow Flag
0000
0011
0100
0110
1000
1010
1101
1110
Subtraction
Sign of value being subtracted (subtrahend)Sign of value being subtracted from (minuend)Sign of resultResulting value of Overflow Flag
0000
0010
0101
0110
1000
1011
1100
1110