3.10.1. B, BL, BX, and BLX

Branch instructions.

Syntax

B{cond} label
BL{cond} label
BX{cond} Rm
BLX{cond} Rm

Where:

B

Is branch (immediate).

BL

Is branch with link (immediate).

BX

Is branch indirect (register).

BLX

Is branch indirect with link (register).

cond

Is an optional condition code. See Conditional execution.

label

Is a PC‑relative expression. See PC‑relative expressions.

Rm

Is a register that indicates an address to branch to. Bit[0] of the value in Rm must be 1, but the address to branch to is created by changing bit[0] to 0.

Operation

All these instructions cause a branch to label, or to the address indicated in Rm. In addition:

  • The BL and BLX instructions write the address of the next instruction to LR (the link register, R14).

  • The BX and BLX instructions result in a UsageFault exception if bit[0] of Rm is 0.

Bcond label is the only conditional instruction that can be either inside or outside an IT block. All other branch instructions must be conditional inside an IT block, and must be unconditional outside the IT block, see IT.

Table 3.14 shows the ranges for the various branch instructions.

Table 3.14. Branch ranges

InstructionBranch range
B label−16 MB to +16 MB
Bcond label (outside IT block)−1 MB to +1 MB
Bcond label (inside IT block)−16 MB to +16 MB
BL{cond} label−16 MB to +16 MB
BX{cond} RmAny value in register
BLX{cond} RmAny value in register

Note

You might have to use the .W suffix to get the maximum branch range. See Instruction width selection.

Restrictions

The restrictions are:

  • Do not use PC in the BLX instruction.

  • For BX and BLX, bit[0] of Rm must be 1 for correct execution but a branch occurs to the target address created by changing bit[0] to 0.

  • When any of these instructions is inside an IT block, it must be the last instruction of the IT block.

Note

Bcond is the only conditional instruction that is not required to be inside an IT block. However, it has a longer branch range when it is inside an IT block.

Condition flags

These instructions do not change the flags.

Examples

    B      loopA  ; Branch to loopA
    BLE    ng     ; Conditionally branch to label ng
    B.W    target ; Branch to target within 16MB range
    BEQ    target ; Conditionally branch to target
    BEQ.W  target ; Conditionally branch to target within 1MB
    BL     funC   ; Branch with link (Call) to function funC, return address
                  ; stored in LR
    BX     LR     ; Return from function call
    BXNE   R0     ; Conditionally branch to address stored in R0
    BLX    R0     ; Branch with link and exchange (Call) to a address stored
                  ; in R0.

Copyright © 2015, 2018 Arm. All rights reserved.ARM DUI 0646C
Non-ConfidentialID121118