cmp

Sizes

byte, word, long

Default Size

word

Affected Flags

X
N
Z
V
C
-
✱
✱
✱
✱

Operands

Op 1
Dn/An/(An)/d(An)/d(An,Xn)/Ea/<label>/d(PC)/d(PC,Xn)/Im
Op 2
Dn/An

Compares the second operand with the first operand, it sets the flags accordingly which will be used by the branching instructions. Works by subtracting the first operand from the second operand and setting the flags. If the second operand is an address register, the CMPA instruction is used instead.

move.l #10, d0
move.l #20, d1
cmp.l d1, d0 ; compares d0 - d1 (sets flags, d0 unchanged)
sgt d2 ; d2 = $FF if d0 > d1, else $00
slt d3 ; d3 = $FF if d0 < d1, else $00
seq d4 ; d4 = $FF if d0 == d1, else $00

* --- Equal values ---
move.l #42, d5
move.l #42, d6
cmp.l d6, d5
seq d7 ; d7 = $FF