Page 86 - ARM 64 Bit Assembly Language
P. 86
Load/store and branch instructions 71
• The <target_label> is encoded as a program-counter-relative offset with 19 bits for a
conditional branch and 26 bits for an unconditional branch. To calculate the correct ad-
dress, the immediate value is first shifted left by two bits and then added to the program
counter.
• The range of the <target_label> is ±1 MB for a conditional branch and ±128 MB for
an unconditional branch.
3.5.1.2 Operations
Name Effect Description
b pc ← target_address Unconditionally move new address
to the program counter (pc).
b<cond> if <cond> then Conditionally move new address to
pc ← target_address the program counter (pc).
end if
3.5.1.3 Examples
Branch to label overflow if the signed overflow flag V is set (meaning if it has a value of 1)
in the PSTATE register:
1 bvs overflow
An unconditional branch is always taken. One example is an endless loop:
1 .text
2 .type main, %function
3 .global main
4 main: b main // Endless loop branching to main
5 ret // Does not return
6 .size main, (. - main)
Conditional branching is often used to implement if statements and other control-flow logic:
1 .text
2 .global main
3 main:
4 stp x29, x30, [sp, #-16]!
5
6 // if (w0 = 0) goto endif1
7 cmp w0, wzr
8 beq endif1
9
10 // w0 = 1