This the multi-page printable view of this section.Click here to print.

Return to the regular view of this page.

Compare Accumulator

Compare Accumulator with Memory

Table of Contents

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-----zc
nSet if most-significant bit of result is set
zSet if result is zero
cSet if register value greater than or equal or Cleared if less than memory value
Instructions
SyntaxOpcode Available on: # of # of Addressing Mode
(hex) 6502 65C02 65816 bytes cycles
CMP #constC9 x x x 21 22 Immediate
CMP addrCD x x x 3 42 Absolute
CMP longCF x 4 52 Absolute Long
CMP dpC5 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,XDD x x x 3 42, 4 Absolute Indexed X
CMP long,XDF x 4 52 Absolute Long Indexed X
CMP addr,YD9 x x x 3 42, 4 Absolute Indexed Y
CMP dp,XD5 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),YD1 x x x 2 52, 3, 4 Direct Page Indirect Indexed Y
CMP [dp],YD7 x 2 62, 3 Direct Page Indirect Long Indexed Y
CMP sr,SC3 x 2 42 Stack Relative
CMP (sr,S),YD3 x 2 72 Stack Relative Indirect Indexed Y

Notes:

  1. 65816: Add 1 byte if m=0 (16-bit memory/accumulator)
  2. 65816: Add 1 cycle if m=0 (16-bit memory/accumulator)
  3. 65816: Add 1 cycle if low byte of Direct Page register is not 0
  4. Add 1 cycle if adding index crosses a page boundary