#include <stdio.h>
int main()
{
printf("a=%d, b=%d, c=%d\n", 1, 2, 3);
return 0;
}
#if 0
/*
* x86 传递3个参数
*/
32bit:eax, ebx, ecx, edx
64bit:rdi, rsi ...
/*
*/
arm 在传递参数时,通常会进行拆分:把前4个参数传递给R0~R3,然后利用栈传递其余参数。
/*
* arm64 传递3个参数
*/
.LC1:
.stirng "a=%d; b=%d, c=%d"
stp x29, x30, [sp, #-16]! # 把FP(X29)和LR(X30)的值推送入栈
add x29, sp, 0 # 构成栈帧
addrp x0, .LC1
add x0, x0, :lo12:.LC1 # 这两条对构建了字符串的指针
#endif
#if 0
/*
* intel
*/
0000000000001149 <main>:
1149: f3 0f 1e fa endbr64
114d: 55 push %rbp
114e: 48 89 e5 mov %rsp,%rbp
1151: b9 03 00 00 00 mov $0x3,%ecx
1156: ba 02 00 00 00 mov $0x2,%edx
115b: be 01 00 00 00 mov $0x1,%esi
1160: 48 8d 3d 9d 0e 00 00 lea 0xe9d(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
1167: b8 00 00 00 00 mov $0x0,%eax
116c: e8 df fe ff ff callq 1050 <printf@plt> // printf(rdi, esi, edx, ecx)
1171: b8 00 00 00 00 mov $0x0,%eax
1176: 5d pop %rbp
1177: c3 retq
1178: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
117f: 00
/*
* arm
*/
000000000040055c <main>:
40055c: a9bf7bfd stp x29, x30, [sp, #-16]!
400560: 910003fd mov x29, sp
400564: 90000000 adrp x0, 400000 <_init-0x3e8>
400568: 9118e000 add x0, x0, #0x638
40056c: 52800063 mov w3, #0x3 // #3
400570: 52800042 mov w2, #0x2 // #2
400574: 52800021 mov w1, #0x1 // #1
400578: 97ffffb6 bl 400450 <printf@plt>
40057c: 52800000 mov w0, #0x0 // #0
400580: a8c17bfd ldp x29, x30, [sp], #16 // printf(w0, w1, w2, w3)
400584: d65f03c0 ret
#endif