A processor doesn't need a separate comparator to compare numbers. It subtracts, throws the difference away, and reads the status flags. A compare instruction does exactly this.
After computing A − B as A + + 1:
- Equal: Z = 1, because the difference is zero.
- Unsigned A < B: C = 0, because a borrow happened. Unsigned A ≥ B: C = 1.
- Signed A < B: = 1. Signed A ≥ B: = 0.
Why N ⊕ V and not just N? If the subtraction didn't overflow, the sign of the difference is right, so N alone answers "is A − B negative?". If it did overflow (V = 1), the sign is flipped, so N is wrong and must be inverted. XOR with V does exactly that.
Greater-than and less-or-equal add Z: unsigned A > B is C = 1 and Z = 0; signed A ≤ B is N ⊕ V = 1 or Z = 1.
One subtraction answers the signed and the unsigned question at the same time. The program picks the flags that match its data type.
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |