Page 146 - ARM 64 Bit Assembly Language
P. 146
132 Chapter 5
Listing 5.24 A larger function call in AArch64 assembly.
1 .section .rodata
2 format:
3 .asciz "The results are: %d %d %d\n"
4 i: .word 120
5 k: .word 122
6 .text
7 .type main, %function
8 .global main
9 main:
10 stp x29, x30, [sp, #-16]! // push FP & LR
11
12 mov w6, #121 // jisinw6
13
14 // printf("The results are: %d %d %d\n", i, j, k)
15 adr x0, format // x0 = &format
16 adr x1, i // x1 = &i
17 ldr w1, [x1] // w1 = i
18 mov w2, w6 // w2 = j
19 adr x3, k // x3 = &k
20 ldr x3, [x3] // w3 = k
21 bl printf // call printf
22
23 // return 0
24 mov w0, #0
25 ldp x29, x30, [sp], #16 // pop FP & LR
26 ret
27 .size main, (. - main)
Listing 5.25 A function call using the stack in C.
1 #include <stdio.h>
2
3 static int i = -1,j=2,k=-3, l=4,m=-5,n=6,o=-7,
4 p=8,q=-9, r=10;
5
6
7 int main(void)
8 {
9 printf("Results: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
10 i, j, k, l, m, n, o, p, q, r);
11 return 0;
12 }