CMN : Compare Negative
CMN permits you to compare two values, automatically updating the flags to reflect the result of the comparison. Internally, CMP subtracts the value of NOT operand two from operand one (effectively an addition).
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).
CMN is important in conditional execution and decision making.
There is also a Compare instruction for comparing regular values.
CMN <op 1>, <op 2>
<flags> = op_1 - (NOT op_2) ; result is not stored, only flags updated
; Have we reached the end of the list? Data is loaded ; into R0, and a value of -1 means we're done. CMN R0, #1 ; compare with -1 BEQ finished ; if true, we're done B next_data ; else, continue through the list
It is necessary to use CMN for comparisons with negative numbers as CMP won't work correctly (due to subtracting a negative becoming an addition). If you attempt an invalid instruction such as
CMP R0, #-1
you may find your assembler either generates an error (bad immediate constant) or, if smarter, substitutes the correct CMN instruction in this case.
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 1||1||op_1||0 0 0 0||op_2/shift|