Control Flow with Branching
BA label- Unconditionally branch tolabelCMP a, b- Compare the values ataandbin order to inform a subsequent branch instruction.BEQ label- Branch tolabelifaandbare equal.BNE label- Branch tolabelifaandbare not equal.BGT label- Branch tolabelifais greater thanb.BGE label- Branch tolabelifais greater than or equal tob.BLT label- Branch tolabelifais less thanb.BLE label- Branch tolabelifais less than or equal tob.
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, R4This 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 SetLO/SS- Unsigned LOwer, Carry ClearHI- Unsigned HIgherLS- Unsigned Lower or SameMI- MInus (negative)PL- PLus (positive, including zero)VS- oVerflow SetVC- 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, R0This 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.