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
C
bit.
- For architectures with a true borrow flag, invert the
V
- Does the result ofa - b
fit within signed 16-bit range?
a
andb
are treated as 16-bit signed numbers.-x
is unary negation.- Entries in columns
Z
,S
,C
, andV
are 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
, thenS
andV
will have the same value (S xnor V
, orS == V
). - If
a < b
, thenS
andV
will 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