Ex6502.CPU.Executor.CMP (ex6502 v0.1.0) View Source

Subtracts the contents of memory from the contents of the accumulator, affecting flags

Operation

A - M

Table

CMP | Compare Memory and Accumulator
================================================

A - M                            N V - B D I Z C
                                 + - - - - - + +

addressing       assembler    opc  bytes  cycles
------------------------------------------------
immediate        CMP #$nn      C9    2     2
absolute         CMP $nnnn     CD    3     4
absolute,X       CMP $nnnn,X   DD    3     4 p
absolute,Y       CMP $nnnn,Y   D9    3     4 p
zeropage         CMP $nn       C5    2     3
zeropage,X       CMP $nn,X     D5    2     4
(zp indirect)    CMP ($nn)     D2    2     5
(zp indirect,X)  CMP ($nn,X)   C1    2     6
(zp indirect),Y  CMP ($nn),Y   D1    2     5 p

p: +1 if page is crossed

Flags

  • Negative: 1 if bit 7 of result is 1; 0 otherwise
  • Carry: 1 if sum of binary exceeds 255 or decimal add exceeds 99; 0 otherwise
  • Zero: 1 if memory is <= accumulator; 0 otherwise

Link to this section Summary

Link to this section Functions