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 ,

68020 only

These forms require the 68020. Select opt p=68020 before any code or data.

Operands

<ea>
An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With opt p=68020, an allowed d(An,Xn) or d(PC,Xn) mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More
Rn
A data or address register, d0 to d7 or a0 to a7. More
(An)+
Memory at an address register, followed by an increase of 1, 2 or 4 bytes for a byte, word or long access. A byte access through sp increases it by 2 to keep it even. 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

An address-register destination uses cmpa.

On the 68020, an immediate source may also be compared with PC-relative memory, as in cmp.w #1, flag(pc). That form assembles as cmpi.

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