cmp

Compare (A32)

CMP<c> <Rn>, <Rm> {, <shift>}

Subtracts two values and updates flags (discarding result).

Details

Computes Rn − (shifted Rm) and updates the N, Z, C, V flags based on the result, but discards the calculated value. Equivalent to a SUBS instruction with no destination register. Restricted to A32 instruction set.

Pseudocode Operation

if ConditionPassed() then
  (result, carry, overflow) ← AddWithCarry(Rn, NOT(shifted_Rm), '1')
  N ← result[31]
  Z ← (result == 0)
  C ← carry
  V ← overflow

Example

CMP r1, r2

Encoding

Binary Layout
cond
00010
10
1
Rn
0
0
0
0
imm5
stype
0
Rm
 
Format Data Proc
Opcode 0x01500000
Extension A32 (Base)

Operands

  • Rn
    First source / base general-purpose register
  • Rm
    Second source / offset general-purpose register

Reference (Arm AArch32 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x03500000 CMP{<c>}{<q>} <Rn>, #<const> A32 cond | 00110 | 10 | 1 | Rn | 0 | 0 | 0 | 0 | imm12
0x2800 CMP{<c>}{<q>} <Rn>, #<imm8> T32 001 | 01 | Rn | imm8
0xF1B00F00 CMP{<c>}.W <Rn>, #<const> T32 11110 | i | 0 | 1101 | 1 | Rn | 0 | imm3 | 1111 | imm8
0x01500060 CMP{<c>}{<q>} <Rn>, <Rm>, RRX A32 cond | 00010 | 10 | 1 | Rn | 0 | 0 | 0 | 0 | 00000 | 11 | 0 | Rm
0x01500000 CMP{<c>}{<q>} <Rn>, <Rm> {, <shift> #<amount>} A32 cond | 00010 | 10 | 1 | Rn | 0 | 0 | 0 | 0 | imm5 | stype | 0 | Rm
0x4280 CMP{<c>}{<q>} <Rn>, <Rm> T32 010000 | 1010 | Rm | Rn
0x4500 CMP{<c>}{<q>} <Rn>, <Rm> T32 010001 | 01 | N | Rm | Rn
0xEBB00F30 CMP{<c>}{<q>} <Rn>, <Rm>, RRX T32 1110101 | 1101 | 1 | Rn | 0 | 000 | 1111 | 00 | 11 | Rm
0xEBB00F00 CMP{<c>}.W <Rn>, <Rm> T32 1110101 | 1101 | 1 | Rn | 0 | imm3 | 1111 | imm2 | stype | Rm
0x01500010 CMP{<c>}{<q>} <Rn>, <Rm>, <type> <Rs> A32 cond | 00010 | 10 | 1 | Rn | 0 | 0 | 0 | 0 | Rs | 0 | stype | 1 | Rm

Description

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

Operation

if ConditionPassed() then
    EncodingSpecificOperations();
    shifted = Shift(R[m], shift_t, shift_n, PSTATE.C);
    (result, nzcv) = AddWithCarry(R[n], NOT(shifted), '1');
    PSTATE.<N,Z,C,V> = nzcv;