cmp

Compare

Subtracts the first operand from the second operand and sets the flags, leaving both unchanged.

Sizes .b .w .l, .w by default

XNZVC –●●●●
  • ● set from the result
  • – not changed

Forms

  • cmp ,

Operands

<ea>
An operand using one of the instruction’s supported addressing modes, such as d0, (a0)+ or 4(a1). It may name a register, memory or an immediate value. More
(An)+
Memory at the address stored in an address register, for example (a0)+. After access, the simulator increases the register by the operation’s size in bytes. More
#imm
An immediate value written after #: a number, character or label, such as #10, #$FF or #'a'. It must fit the operation’s size: byte -128 to 255, word -32768 to 65535, or long -2147483648 to 4294967295; signed and unsigned spellings are accepted. More

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