Revision as of 15:34, 27 November 2011
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.
CMP <op 1>, <op 2>
= op_1 - op_2 ; result is not stored, only flags updated
; 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 ('.')
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|