When performing a CMP instruction (which computes A - M), the 6502 sets the Negative (N) and Overflow (V) flags. For signed comparisons, when N = V, it means A ≥ M (signed). But why?
The answer lies in understanding how two's complement arithmetic works and what the overflow flag actually tells us about the sign bit.
Why This Works: Two's Complement Arithmetic
CMP performs subtraction: When you execute CMP #$E2, the 6502 computes A - M internally as A + (~M + 1) using two's complement negation.
Overflow means the sign bit "lied": The V flag is set when adding two numbers with the same sign produces a result with the opposite sign - this is overflow.
N = V catches the truth: When both flags match, either they're both correctly showing a positive result (N=0, V=0) or they're both showing that an overflow inverted what should be positive (N=1, V=1).
No single branch instruction: The 6502 doesn't have a "branch if N = V" instruction, so you need to use a sequence like checking with BIT or using EOR to compare the flags.