Control Flow with Branching

  • BA label - Unconditionally branch to label
  • CMP a, b - Compare the values at a and b in order to inform a subsequent branch instruction.
  • BEQ label - Branch to label if a and b are equal.
  • BNE label - Branch to label if a and b are not equal.
  • BGT label - Branch to label if a is greater than b.
  • BGE label - Branch to label if a is greater than or equal to b.
  • BLT label - Branch to label if a is less than b.
  • BLE label - Branch to label if a is less than or equal to b.

Warning

Conditional Execution is mostly deprecated as of ARMv8 so should be used with caution.

Conditional Execution of General Instructions

Many instructions can have a suffix appended so that they are conditionally executed based on a previous comparison instruction:
CMP R0, R1
ADDEQ R2, R3, R4

This example adds the value in R3 to the value in R4 and stores the result in R2, only if the value in R0 is equal to the value in R1.

The conditional branch instructions given above are in fact not distinct instructions, but the same B instruction with different suffixes to define the condition.

The following suffixes can be applied to most mnemonics: AL (or blank), EQ, NE, GT, GE, LT, LE (as above), as well as:

  • HS/CS - Unsigned Higher or Same, Carry Set
  • LO/SS - Unsigned LOwer, Carry Clear
  • HI - Unsigned HIgher
  • LS - Unsigned Lower or Same
  • MI - MInus (negative)
  • PL - PLus (positive, including zero)
  • VS - oVerflow Set
  • VC - oVerflow Clear

Setting Flags for Conditional Execution from General Instructions

Many instructions can have a suffix of S appended so that status flags are set as a result of the operation to inform conditional execution of a subsequent instruction:
SUBS R0, R1, R2
ADDGT R0, R0, R0

This example subtracts the value in R2 from the value in R1 and stores the result in R0, then doubles the value in R0 only if the value in R2 is greater than the value in R1.