写一个测试函数,关闭优化,编译为release版本
int test(int a,int b,int c,int d,int e,int f)
{
return a + b + c + d + e + f;
}
.text:00000001400010B0 ; void t1(void)
.text:00000001400010B0 ?t1@@YAXXZ proc near ; CODE XREF: main+1C↓p
.text:00000001400010B0 ; DATA XREF: .pdata:000000014000400C↓o
.text:00000001400010B0
.text:00000001400010B0 e = dword ptr -18h
.text:00000001400010B0 f = dword ptr -10h
.text:00000001400010B0
.text:00000001400010B0 sub rsp, 38h
.text:00000001400010B4 mov dword ptr [rsp+28h], 6 ; f
.text:00000001400010BC mov dword ptr [rsp+20h], 5 ; e
.text:00000001400010C4 mov r9d, 4 ; d
.text:00000001400010CA mov r8d, 3 ; c
.text:00000001400010D0 mov edx, 2 ; b
.text:00000001400010D5 mov ecx, 1 ; a
.text:00000001400010DA call ?test@@YAHHHHHHH@Z ; test(int,int,int,int,int,int)
.text:00000001400010DF add rsp, 38h
.text:00000001400010E3 retn
.text:00000001400010E3 ?t1@@YAXXZ endp
从上图可以看出在函数调用函数前, 前4个参数在rcx rdx r8 r9,从第5个参数开始就在栈中,
第5个参数 rsp+20h 第6个参数rsp+28h.
进入到函数第一句代码时,第5个参数在28h,第6个参数在30h