我正在分析C ++中的简单应用程序:
int add(int a, int b)
{
return a + b;
}
int main()
{
int res = add(5, 8);
return 0;
}
以调试模式编译的反汇编如下:
5:
6: int main()
7: {
00007FF736F42300 push rbp
00007FF736F42302 push rdi
00007FF736F42303 sub rsp,108h
00007FF736F4230A lea rbp,[rsp+20h]
00007FF736F4230F mov rdi,rsp
00007FF736F42312 mov ecx,42h
00007FF736F42317 mov eax,0CCCCCCCCh
00007FF736F4231C rep stos dword ptr [rdi]
8: int res = add(5, 8);
00007FF736F4231E mov edx,8
00007FF736F42323 mov ecx,5
00007FF736F42328 call add (07FF736F4137Ah)
00007FF736F4232D mov dword ptr [res],eax
9:
10: return 0;
00007FF736F42330 xor eax,eax
11: }
00007FF736F42332 lea rsp,[rbp+0E8h]
00007FF736F42339 pop rdi
00007FF736F4233A pop rbp
00007FF736F4233B ret
让我感兴趣的是,调用add函数实际上并不调用add函数本身:
00007FF736F42328 call add (07FF736F4137Ah)
转到:
add:
00007FF736F4137A jmp add (07FF736F41AA0h)
然后终于跳到:
1: int add(int a, int b)
2: {
00007FF736F41AA0 mov dword ptr [rsp+10h],edx
00007FF736F41AA4 mov dword ptr [rsp+8],ecx
00007FF736F41AA8 push rbp
00007FF736F41AA9 push rdi
(...)
为什么会有这个中点跳?为什么调用不立即添加功能实现?