Apple II Overflow Flags
6502 Carry vs Overflow Flags
Input Values
Hex
$7F
Unsigned
127
Signed
+127
Hex
$01
Unsigned
1
Signed
+1
Binary Operation
Bit:
7 6 5 4 3 2 1 0
Carries:
A:
+
=
Flag Results
Carry Flag (C)
0
No carry out of bit 7
Overflow Flag (V)
0
Carry in = carry out
Result Interpretations
Unsigned Arithmetic
127 + 1 = 128
✓ Valid (0-255)
Signed Arithmetic
+127 + 1 = -128
✗ Overflow!
Example Cases
Understanding the Flags
Carry Flag (C)
- • Detects unsigned arithmetic overflow
- • Set when result > 255 (addition)
- • Set when result < 0 (subtraction)
- • Simply the carry/borrow out of bit 7
- • Use for unsigned comparisons
Overflow Flag (V)
- • Detects signed arithmetic overflow
- • Set when sign bit is wrong
- • V = (carry into bit 7) XOR (carry out of bit 7)
- • Positive + Positive = Negative → overflow
- • Negative + Negative = Positive → overflow
Key Insight: The carry flag is for unsigned math (0-255), while the overflow flag is for signed math (-128 to +127).
They use different detection methods because they're solving different problems!