CMP
From ARMwiki
(Difference between revisions)
(Created.) |
m (Added link to CMN.) |
||
Line 15: | Line 15: | ||
'''''CMP''''' is important in conditional execution and decision making. | '''''CMP''''' is important in conditional execution and decision making. | ||
+ | |||
+ | There is also a [[CMN|Compare Negative]] instruction for comparing negated values. | ||
===Syntax=== | ===Syntax=== | ||
− | CMP <op 1>, <op 2> | + | CMP<suffix> <op 1>, <op 2> |
===Function=== | ===Function=== | ||
− | = op_1 - op_2 | + | <flags> = op_1 - op_2 ; result is not stored, only flags updated |
===Example=== | ===Example=== |
Revision as of 16:44, 27 November 2011
Instruction | CMP |
---|---|
Function | Compare |
Category | Data processing |
ARM family | All |
Notes | - |
Contents |
CMP
CMP permits you to compare two values, automatically updating the flags to reflect the result of the comparison. Internally, CMP subtracts the value of operand two from operand one.
Operand 1 is a register, operand 2 may be a register, shifted register, or an immediate value (which may be shifted).
There is no S bit, it is implied. The N, Z, V, and C flags are updated as usual (N - result bit 31, Z if result zero, V if overflow, C if NOT borrow).
CMP is important in conditional execution and decision making.
There is also a Compare Negative instruction for comparing negated values.
Syntax
CMP<suffix> <op 1>, <op 2>
Function
<flags> = op_1 - op_2 ; result is not stored, only flags updated
Example
; Mask off control codes, R0 is ASCII code. Passes high-ASCII. CMP R0, #32 ; compare with 32 (space) MOVLT R0, #46 ; if less, replace with 46 ('.') CMP R0, #127 ; compare with 127 (backspace) MOVEQ R0, #46 ; if equal, replace with 46 ('.')
Technical
The instruction bit pattern is as follows:
31 - 28 | 27 | 26 | 25 | 24 - 21 | 20 | 19 - 16 | 15 - 12 | 11 - 0 |
---|---|---|---|---|---|---|---|---|
condition | 0 | 0 | I | 1 0 1 0 | 1 | op_1 | 0 0 0 0 | op_2/shift |