Most data processing instructions update the condition flags in the Application Program Status Register (APSR) according to the result of the operation, see Application Program Status Register. Some instructions update all flags, and some only update a subset. If a flag is not updated, the original value is preserved. See the instruction descriptions for the flags they affect.
You can execute a conditional branch instruction, based on the condition flags set in another instruction, either:
immediately after the instruction that updated the flags
after any number of intervening instructions that have not updated the flags.
On the Cortex-M0+ processor, conditional execution is available by using conditional branches.
This section describes:
The APSR contains the following condition flags:
Set to 1 when the result of the operation was negative, cleared to 0 otherwise.
Set to 1 when the result of the operation was zero, cleared to 0 otherwise.
Set to 1 when the operation resulted in a carry, cleared to 0 otherwise.
Set to 1 when the operation caused overflow, cleared to 0 otherwise.
For more information about the APSR see Program Status Register.
A carry occurs:
if the result of an addition is greater than or equal to 232
if the result of a subtraction is positive or zero
as the result of a shift or rotate instruction.
Overflow occurs when the sign of the result, in bit, 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
or adding, for
CMN, except that the result is discarded.
See the instruction descriptions for more information.
Conditional branch is shown in syntax descriptions as
A branch instruction with a condition code is only taken if the
condition code flags in the APSR meet the specified condition, otherwise
the branch instruction is ignored. Table 3.4 shows the condition codes to use.
Table 3.4 also shows the relationship between condition code suffixes and the N, Z, C, and V flags.
|Z = 1||Equal, last flag setting result was zero|
|Z = 0||Not equal, last flag setting result was non-zero|
|C = 1||Higher or same, unsigned|
|C = 0||Lower, unsigned|
|N = 1||Negative|
|N = 0||Positive or zero|
|V = 1||Overflow|
|V = 0||No overflow|
|C = 1 and Z = 0||Higher, unsigned|
|C = 0 or Z = 1||Lower or same, unsigned|
|N = V||Greater than or equal, signed|
|N != V||Less than, signed|
|Z = 0 and N = V||Greater than, signed|
|Z = 1 and N != V|
Less than or equal, signed
|Can have any value||Always. This is the default when no suffix is specified.|