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
- The bigger of two numbersM68K assembly
- The largest elementM68K assembly
- Reverse a string in placeM68K assembly
- Recursion: factorial and FibonacciM68K assembly
- Bubble sortM68K assembly
- Binary searchM68K assembly
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)+or4(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,#$FFor#'a'. It must fit the operation’s size: byte-128to255, word-32768to65535, or long-2147483648to4294967295; 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