Branch instructions.
B{cond
}label
BL label
BX Rm
BLX Rm
where:
-
cond
-
Is an optional condition code, see Conditional execution.
-
label
-
Is a PC-relative expression. See PC‑relative expressions.
-
Rm
-
Is a register providing the address to branch to.
All these instructions cause a branch to the address indicated
by
or contained
in the register specified by label
.
In addition:Rm
-
The
BL
andBLX
instructions write the address of the next instruction to LR, the link register R14. -
The
BX
andBLX
instructions result in a HardFault exception if bit[0] of
is 0.Rm
BL
and BLX
instructions also set
bit[0] of the LR to 1. This ensures that the value is suitable for use
by a subsequent POP {PC}
or BX
instruction
to perform a successful return branch.
Table 3.9 shows the ranges for the various branch instructions.
Instruction | Branch range |
---|---|
|
−2 KB to +2 KB. |
B
|
−256 bytes to +254 bytes. |
BL
|
−16 MB to +16 MB. |
BX
|
Any value in register. |
BLX
|
Any value in register. |
In these instructions:
-
Do not use SP or PC in the
BX
orBLX
instruction. -
For
BX
andBLX
, bit[0] of
must be 1 for correct execution. Bit[0] is used to update the EPSR T-bit and is discarded from the target address.Rm
Note
B
is the only
conditional instruction on the Cortex-M0+ processor.cond
B loopA ; Branch to loopA BL funC ; Branch with link (Call) to function funC, return address ; stored in LR BX LR ; Return from function call BLX R0 ; Branch with link and exchange (Call) to a address stored ; in R0 BEQ labelD ; Conditionally branch to labelD if last flag setting ; instruction set the Z flag, else do not branch.