cmp
Compare
Subtracts the first operand from the second operand and sets the flags, leaving both unchanged.
Sizes .b .w .l, .w by default
Used in
- The condition code registerM68K assembly
- Compare and branchM68K assembly
- Loops and dbraM68K assembly
- The screen, keyboard and mouse through trapsM68K assembly
- Interrupts and cyclesM68K assembly
- The bigger of two numbersM68K assembly
- The largest elementM68K assembly
- Reverse a string in placeM68K assembly
- Recursion: factorial and FibonacciM68K assembly
- Bubble sortM68K assembly
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 allowedd(An,Xn)ord(PC,Xn)mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More Rn- A data or address register,
d0tod7ora0toa7. 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
spincreases it by 2 to keep it even. More #imm- An immediate value written after
#: a number, character or label, such as#10,#$FFor#'a'. It must fit the operation’s size: byte-128to255, word-32768to65535, or long-2147483648to4294967295; signed and unsigned spellings are accepted. More
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