2.6.3.7 Conditional Execution

Most data processing instructions can optionally update the condition flags in the Application Program Status Register (APSR) according to the result of the operation; see 2.5.1.3.6 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 an instruction conditionally, 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.

Conditional execution is available by using conditional branches or by adding condition code suffixes to instructions. For a list of the suffixes to add to instructions to make them conditional instructions, see Table 2-23. The condition code suffix enables the processor to test a condition based on the flags. If the condition test of a conditional instruction fails, the instruction:

  • Does not execute
  • Does not write any value to its destination register
  • Does not affect any of the flags
  • Does not generate any exception.

Conditional instructions, except for conditional branches, must be inside an If-Then instruction block. See 2.6.9.3 IT for more information and restrictions when using the IT instruction. Depending on the vendor, the assembler might automatically insert an IT instruction if you have conditional instructions outside the IT block.

Use the CBZ and CBNZ instructions to compare the value of a register against zero and branch on the result.

This section describes the condition flags and condition code suffixes.