ARM64中函数调用的基本过程

1、C语言代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//
//  main.m
//  lldb
//
//  Created by 余西安 on 2018/11/1.
//  Copyright © 2018 yusian. All rights reserved.
//
 
void func()
{
 
}
void asmFunction()
{
    int a = 10;
    int b = 12;
    func();
}
int main() {
    asmFunction();
}

2、ARM64汇编代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0x100032758 <+0>:  sub    sp, sp, #0x20          ;申请局部变量空间
 
0x10003275c <+4>:  stp    x29, x30, [sp, #0x10]  ; 保护fp,lr
0x100032760 <+8>:  add    x29, sp, #0x10         ; fp 
 
0x100032764 <+12>: orr    w8, wzr, #0xc          ; w8 = 12
0x100032768 <+16>: mov    w9, #0xa               ; w9 = 10
0x10003276c <+20>: stur   w9, [x29, #-0x4]       ; int a = 10;
0x100032770 <+24>: str    w8, [sp, #0x8]         ; int b = 12
 
0x100032774 <+28>: bl     0x100032754            ; func()
 
0x100032778 <+32>: ldp    x29, x30, [sp, #0x10]  ; 恢复fp,lr
0x10003277c <+36>: add    sp, sp, #0x20          ; 恢复sp
0x100032780 <+40>: ret

Leave a Reply