ARM > Introduction to ARM > Branch Instructions
Examples of Branch Instructions
Branching forward, to skip over some code:
... ; some code here
B fwd ; jump to label 'fwd'
... ; more code here
fwd
Branching backwards, creating a loop:
back
... ; more code here
B back ; jump to label 'back'
Using BL
to call a subroutine:
...
...
BL calc ; call 'calc'
... ; returns to here
...
calc ; function body
ADD r0, r1, r2 ; do some work here
MOV pc, r14 ; PC = R14 to return
Remarks
Branches are PC-relative. +/-32M range (24 bits × 4 bytes).
Since ARM’s branch instructions are PC-relative the code produced is position independent — it can execute from any address in memory. Certain systems such as BREW take advantage of this to avoid the need for an MMU.
How can we perform longer branches which access the full 32-bit address space? You can set up the LR manually if needed, then load into PC:
MOV lr,pc
LDR pc,=dest