You copied the Doc URL to your clipboard.

3.3.6. Conditional execution

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 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.

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[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.

Condition code suffixes

Conditional branch is shown in syntax descriptions as B{cond}. 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.

Table 3.4. Condition code suffixes
SuffixFlagsMeaning
EQZ = 1Equal, last flag setting result was zero.
NEZ = 0Not equal, last flag setting result was non-zero.
CS or HSC = 1Higher or same, unsigned.
CC or LOC = 0Lower, unsigned.
MIN = 1Negative.
PLN = 0Positive or zero.
VSV = 1Overflow.
VCV = 0No overflow.
HIC = 1 and Z = 0Higher, unsigned.
LSC = 0 or   Z = 1Lower or same, unsigned.
GEN = V Greater than or equal, signed.
LTN != VLess than, signed.
GTZ = 0 and N = VGreater than, signed.
LEZ = 1 or N != V

Less than or equal, signed.

ALCan have any valueAlways. This is the default when no suffix is specified.

Was this page helpful? Yes No