cmp
Compare (A32)
CMP<c> <Rn>, <Rm> {, <shift>}
Subtracts two values and updates flags (discarding result).
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
31:28
00010
27:23
10
22:21
1
20
Rn
19:16
0
15
0
14
0
13
0
12
imm5
11:7
stype
6:5
0
4
Rm
3:0
Operands
-
Rn
First source / base general-purpose register -
Rm
Second source / offset general-purpose register
Reference
View in Arm A64 ISA 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;