Page 88 - ARM 64 Bit Assembly Language
P. 88
Load/store and branch instructions 73
The return from procedure instruction, ret, uses the procedure link register x30 to return
when no register is specified:
1 .text
2 .type main, %function
3 .global main
4 main:
5 // Save values of registers x29, x30 to the stack
6 stp x29, x30, [sp, #-16]!
7
8 // Program code
9 // ...
10
11 // Restore values of registers x29, x30 from the stack
12 ldp x29, x30, [sp], #16
13 // Return from subroutine to address in x30
14 ret x30
15 .size main, (. - main)
The return instruction ret x30 is the same as just ret.
3.5.3 Branch and link
The branch and link instructions are used to call subroutines:
bl Branch and Link and
blr Branch to Register and Link.
The branch and link instruction is identical to the branch instruction, except that it copies the
current program counter to the link register before performing the branch. The branch to reg-
ister and link instruction does the same thing, except that it branches to the address contained
in a specified register. This allows the programmer to copy the link register back into the pro-
gram counter at some later point with the ret instruction. This is how subroutines are called,
and how subroutines return and resume executing at the next instruction after the one that
called them.
3.5.3.1 Syntax
bl <target_address>
blr Xn
• The target_address can be any label in the current file, or any label that is defined as
.global or .globl in any file that is linked in, within a range of ±128 MB.