cmp

Compare (Immediate)

CMP <Wn>, #<imm>

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

Details

Subtracts a 12-bit immediate value from a register and updates the condition flags based on the result; the result itself is discarded. This is an alias for SUBS with destination WZR. Sets N, Z, C, V flags according to the subtraction result. Executes in AArch64 state only.

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
1
1
100010
sh
imm12
Rn
11111
 
Format Data Processing
Opcode 0x7100001F
Extension Base

Operands

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

Reference (Arm A64 ISA)

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.