CMP Instruction



CMP (CoMPare) compares a data register with an effective address. The flags are affected the same way as if the effective address was subtracted from the data register. None of the operands are changed. Often used with the Bcc instruction. An example:

CMP D0,D1
BGT X1

The program will branch to X1 if D1 is greater than D0, else the program will continue.
ADDRESS METHODS: Dn, An, (An), (An)+, -(An), x(An), x(An,xr.s), x.w, x.l, x(PC), x(PC,xr.s), #x

DATA LENGTH: Byte, word, longword

Byte can't be used when comparing to an address register.

FLAGS: X - U
N - S
Z - S
C - Set if a borrow was needed when subtracting, otherwise it is cleared.
V - S

SYNTAX: CMP <ea>,Dn

There are four CMP instructions, CMP, CMPA, CMPI and CMPM. The compiler often chooses the right instruction, so you can write CMP all the time if you want.

   CMP    #2,D0    compares D0 to #2 and sets CCR flags accordingly