Condition Codes
Here's another problem: if we solve the problem of results that are
too big by throwing away the carry, how do we know what happened? We
introduce another register, called the Condition Code register. It is
used to keep information regarding the results of arithmetic
operations, so we can look at them later. There are four condition
codes:
- N: was the result negative?
- Z: was the result zero?
- V: was there an overflow (added two positive numbers and got
negative, or vice versa)?
- C: was there a carry-out?
Notice that carry-out and overflow are not at all the same thing!
We can see some combinations of the four condition codes, in four-bit signed
hexadecimal addition:
2 | f | 6 |
a | b | 4 |
+2 | +f | +6 | +a |
+1 | +c |
4 | e | c | 4 | c | 0 |
N = 0 | N = 1 | N = 1 | N = 0 |
N = 1 | N = 0 |
Z = 0 | Z = 0 | Z = 0 | Z = 0 |
Z = 0 | Z = 1 |
V = 0 | V = 0 | V = 1 | V = 1 |
V = 0 | V = 0 |
C = 0 | C = 1 | C = 0 | C = 1 |
C = 0 | C = 1 |