CMP subtracts the data at the address in the operand from the contents of the accumulator,
setting the n, z & c flags based on the result.
The Accumulator & Memory are unaffected by this operation.
Data size
On all processors, the data added from memory is 8-bit.
However, for 16-bit processors with the m flag is clear then the data added is 16-bit
with the low-order 8-bits at the effective address and the high-order 8-bits at the effective address plus one.
Flags Affected
Flags | |
---|
n | Set if most-significant bit of result is set |
---|
z | Set if result is zero |
---|
c | Set if register value greater than or equal or Cleared if less than memory value |
Instructions
Syntax | Opcode |
Available on: |
# of |
# of |
Addressing Mode |
(hex) |
6502 |
65C02 |
65816 |
bytes |
cycles |
CMP #const | C9 |
x |
x |
x |
21 |
22 |
Immediate |
CMP addr | CD |
x |
x |
x |
3 |
42 |
Absolute |
CMP long | CF |
|
|
x |
4 |
52 |
Absolute Long |
CMP dp | C5 |
x |
x |
x |
2 |
32, 3 |
Direct Page |
CMP (dp) | D2 |
|
x |
x |
2 |
52, 3 |
Direct Page Indirect |
CMP [dp] | C7 |
|
|
x |
2 |
62, 3 |
Direct Page Indirect Long |
CMP addr,X | DD |
x |
x |
x |
3 |
42, 4 |
Absolute Indexed X |
CMP long,X | DF |
|
|
x |
4 |
52 |
Absolute Long Indexed X |
CMP addr,Y | D9 |
x |
x |
x |
3 |
42, 4 |
Absolute Indexed Y |
CMP dp,X | D5 |
x |
x |
x |
2 |
42, 3 |
Direct Page Indexed X |
CMP (dp,X) | C1 |
x |
x |
x |
2 |
62, 3 |
Direct Page Indexed Indirect X |
CMP (dp),Y | D1 |
x |
x |
x |
2 |
52, 3, 4 |
Direct Page Indirect Indexed Y |
CMP [dp],Y | D7 |
|
|
x |
2 |
62, 3 |
Direct Page Indirect Long Indexed Y |
CMP sr,S | C3 |
|
|
x |
2 |
42 |
Stack Relative |
CMP (sr,S),Y | D3 |
|
|
x |
2 |
72 |
Stack Relative Indirect Indexed Y |
Notes:
- 65816: Add 1 byte if m=0 (16-bit memory/accumulator)
- 65816: Add 1 cycle if m=0 (16-bit memory/accumulator)
- 65816: Add 1 cycle if low byte of Direct Page register is not 0
- Add 1 cycle if adding index crosses a page boundary