Page 89 - ARM 64 Bit Assembly Language
P. 89
74 Chapter 3
3.5.3.2 Operations
Name Effect Description
bl X30 ← pc + 4 Save address of next instruction in
pc ← target_address link register (X30), then load pc with
new address
blr X30 ← pc + 4 Save address of next instruction in
pc ← Xn link register (X30), then load pc with
Xn
3.5.3.3 Examples
The following C code uses the printf function from the C Standard Library to print a mes-
sage to standard output.
1 int main(void)
2 {
3 printf("hello, world!\n");
4 return 0;
5 }
The equivalent ARM assembly code uses the bl instruction call printf:
1 .section .rodata
2 msg:
3 .asciz "Hello, world!\n" // Declare our message
4 .text
5 .type main, %function
6 .global main
7 main:
8 stp x29, x30, [sp, #-16]! // push link register (and x30) to stack
9
10 // printf("hello, world\n")
11 // Note: the following call to printf will change the link
12 // register, but we saved it on the stack.
13 ldr x0, =msg
14 bl printf // Branch and Link to printf
15
16
17 mov w0, 0 // return 0
18
19 ldp x29, x30, [sp], #16 // pop link register (and x30) from stack
20 ret
21 .size main, (. - main)