The Cortex-M4 Instruction Set
ARM DUI 0553A Copyright © 2010 ARM. All rights reserved. 3-19
ID121610 Non-Confidential
The condition flags
The APSR contains the following condition flags:
N Set to 1 when the result of the operation was negative, cleared to 0 otherwise.
Z Set to 1 when the result of the operation was zero, cleared to 0 otherwise.
C Set to 1 when the operation resulted in a carry, cleared to 0 otherwise.
V Set to 1 when the operation caused overflow, cleared to 0 otherwise.
For more information about the APSR see Program Status Register on page 2-4.
A carry occurs:
• if the result of an addition is greater than or equal to 2
32
• if the result of a subtraction is positive or zero
• as the result of an inline barrel shifter operation in a move or logical instruction.
Overflow occurs when the sign of the result, in bit[31], does not match the sign of the result had
the operation been performed at infinite precision, for example:
• if adding two negative values results in a positive value
• if adding two positive values results in a negative value
• if subtracting a positive value from a negative value generates a positive value
• if subtracting a negative value from a positive value generates a negative value.
The Compare operations are identical to subtracting, for
CMP
, or adding, for
CMN
, except that the
result is discarded. See the instruction descriptions for more information.
Most instructions update the status flags only if the S suffix is specified. See the instruction
descriptions for more information.
Condition code suffixes
The instructions that can be conditional have an optional condition code, shown in syntax
descriptions as
{cond}
. Conditional execution requires a preceding
IT
instruction. An instruction
with a condition code is only executed if the condition code flags in the APSR meet the specified
condition. Table 3-4 shows the condition codes to use.
You can use conditional execution with the
IT
instruction to reduce the number of branch
instructions in code.
Table 3-4 also shows the relationship between condition code suffixes and the N, Z, C, and V
flags.
Table 3-4 Condition code suffixes
Suffix Flags Meaning
EQ
Z = 1 Equal
NE
Z = 0 Not equal
CS or HS
C = 1 Higher or same, unsigned
CC or LO
C = 0 Lower, unsigned
MI
N = 1 Negative
PL
N = 0 Positive or zero