Z- Is the result zero?S- Is the top bit of the result set?C- Did a borrow not occur (see Subtraction on the 6502)?- For architectures with a true borrow flag, invert the
Cbit.
- For architectures with a true borrow flag, invert the
V- Does the result ofa - bfit within signed 16-bit range?
aandbare treated as 16-bit signed numbers.-xis unary negation.- Entries in columns
Z,S,C, andVare boolean expressions that evaluate to the value of each flag.
| Condition | Z | S | C | V |
|---|---|---|---|---|
| a > 0, b > 0, a >= b | a == b | 0 | 1 | 0 |
| a > 0, b > 0, a < b | 0 | 1 | 0 | 0 |
| a > 0, b < 0 (a > b) | 0 | a + -b > 32767 | 0 | a + -b > 32767 |
| a < 0, b > 0 (a < b) | 0 | a - b >= -32768 | 1 | a - b < -32768 |
| a < 0, b < 0, a >= b | a == b | 0 | 1 | 0 |
| a < 0, b < 0, a < b | 0 | 1 | 0 | 0 |
- If
a >= b, thenSandVwill have the same value (S xnor V, orS == V). - If
a < b, thenSandVwill have opposite values (S xor V). - By using only the first table entry, you can derive flags for unsigned compares too!
- If
a >= b, thenC == 1. - If
a < b, thenC == 0.
- If