cmp

Compare (Immediate)

CMP <Wn>, #<imm>

Subtracts immediate from register, updates flags (discard result). (Alias for SUBS)

Pseudocode Operation

result ← Wn - imm
N ← result[31]
Z ← (result == 0)
C ← NOT(BorrowFrom(Wn - imm))
V ← OverflowFrom(Wn - imm)

Example

CMP w1, #16

Encoding

Binary Layout
0
31
1
30
1
29
100010
28:23
sh
22
imm12
21:10
Rn
9:5
11111
4:0
 
Format Data Processing
Opcode 0x7100001F
Extension Base

Operands

  • Wn
    First source / base 32-bit integer register
  • imm
    Imm

Related

Other forms of cmp

  • cmp Compare (A32)

More in Base

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x6B20001F CMP <Wn|WSP>, <Wm>{, <extend> {#<amount>}} A64 0 | 1 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | 11111
0xEB20001F CMP <Xn|SP>, <R><m>{, <extend> {#<amount>}} A64 1 | 1 | 1 | 01011 | 00 | 1 | Rm | option | imm3 | Rn | 11111
0x7100001F CMP <Wn|WSP>, #<imm>{, <shift>} A64 0 | 1 | 1 | 100010 | sh | imm12 | Rn | 11111
0xF100001F CMP <Xn|SP>, #<imm>{, <shift>} A64 1 | 1 | 1 | 100010 | sh | imm12 | Rn | 11111
0x6B00001F CMP <Wn>, <Wm>{, <shift> #<amount>} A64 0 | 1 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | 11111
0xEB00001F CMP <Xn>, <Xm>{, <shift> #<amount>} A64 1 | 1 | 1 | 01011 | shift | 0 | Rm | imm6 | Rn | 11111

Description

Compare (immediate) subtracts an optionally-shifted immediate value from a register value. It updates the condition flags based on the result, and discards the result.