首页
社区
课程
招聘
[原创]对于函数栈帧的理解
发表于: 2020-3-7 16:56 2120

[原创]对于函数栈帧的理解

2020-3-7 16:56
2120

c代码

int add(int x, int y)
{
    return x + y;
}

int main()
{
    int i = 3, j=4, k;
    k = add(i, j);
    printf("%d %d", j, k);
    return 0;
}

对应汇编代码

int add(int x, int y)
{
00472050  push        ebp  
00472051  mov         ebp,esp  
00472053  sub         esp,0C0h  
00472059  push        ebx  
0047205A  push        esi  
0047205B  push        edi  
0047205C  lea         edi,[ebp-0C0h]  
00472062  mov         ecx,30h  
00472067  mov         eax,0CCCCCCCCh  
0047206C  rep stos    dword ptr es:[edi]  
0047206E  mov         ecx,offset _E4390A93_ConsoleApplication3@cpp (047C026h)  
00472073  call        @__CheckForDebuggerJustMyCode@4 (0471221h)  
    return x + y;
00472078  mov         eax,dword ptr [x]  
0047207B  add         eax,dword ptr [y]  
}
0047207E  pop         edi  
0047207F  pop         esi  
}
00472080  pop         ebx  
00472081  add         esp,0C0h  
00472087  cmp         ebp,esp  
00472089  call        __RTC_CheckEsp (047122Bh)  
0047208E  mov         esp,ebp  
00472090  pop         ebp  
00472091  ret  
}


int main()
{
00471990  push        ebp  
00471991  mov         ebp,esp  
00471993  sub         esp,0E4h  
00471999  push        ebx  
0047199A  push        esi  
0047199B  push        edi  
0047199C  lea         edi,[ebp-0E4h]  
004719A2  mov         ecx,39h  
004719A7  mov         eax,0CCCCCCCCh  
004719AC  rep stos    dword ptr es:[edi]  
004719AE  mov         ecx,offset _E4390A93_ConsoleApplication3@cpp (047C026h)  
004719B3  call        @__CheckForDebuggerJustMyCode@4 (0471221h)  
    int i = 3, j=4, k;
004719B8  mov         dword ptr [i],3  
004719BF  mov         dword ptr [j],4  
    k = add(i, j);
004719C6  mov         eax,dword ptr [j]  
004719C9  push        eax  
004719CA  mov         ecx,dword ptr [i]  
004719CD  push        ecx  
004719CE  call        add (0471393h)  
004719D3  add         esp,8  
004719D6  mov         dword ptr [k],eax  
    printf("%d %d", j, k);
004719D9  mov         eax,dword ptr [k]  
004719DC  push        eax  
004719DD  mov         ecx,dword ptr [j]  
004719E0  push        ecx  
004719E1  push        offset string "%d %d" (0477B30h)  
004719E6  call        _printf (0471046h)  
004719EB  add         esp,0Ch  
    return 0;
004719EE  xor         eax,eax  
}
004719F0  pop         edi  
004719F1  pop         esi  
004719F2  pop         ebx  
004719F3  add         esp,0E4h  
004719F9  cmp         ebp,esp  
004719FB  call        __RTC_CheckEsp (047122Bh)  
00471A00  mov         esp,ebp  
00471A02  pop         ebp  
00471A03  ret

函数开始调用:

调用函数开始:

函数结束:


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 729
活跃值: (388)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
2020-3-7 18:01
0
雪    币: 288
活跃值: (269)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
实践是成功之母
2020-3-8 09:36
0
游客
登录 | 注册 方可回帖
返回
//