int _tmain(int argc, _TCHAR* argv[])
{
00BB1400 55 push ebp
00BB1401 8B EC mov ebp,esp
00BB1403 81 EC C0 00 00 00 sub esp,0C0h
00BB1409 53 push ebx
00BB140A 56 push esi
00BB140B 57 push edi
00BB140C 8D BD 40 FF FF FF lea edi,[ebp-0C0h]
00BB1412 B9 30 00 00 00 mov ecx,30h
00BB1417 B8 CC CC CC CC mov eax,0CCCCCCCCh
00BB141C F3 AB rep stos dword ptr es:[edi]
add(1, 2);
00BB141E 6A 02 push 2
00BB1420 6A 01 push 1
-----------------------------------------------------------------------> 参数压栈
00BB1422 E8 B9 FD FF FF call add (0BB11E0h)
00BB1427 83 C4 08 add esp,8 (因为上面压入了两个int所以这里平8字节)
-----------------------------------------------------------------------> 外平栈
return 0;
00BB142A 33 C0 xor eax,eax
}
00BB142C 5F pop edi
00BB142D 5E pop esi
00BB142E 5B pop ebx
00BB142F 81 C4 C0 00 00 00 add esp,0C0h
00BB1435 3B EC cmp ebp,esp
00BB1437 E8 09 FD FF FF call __RTC_CheckEsp (0BB1145h)
00BB143C 8B E5 mov esp,ebp
00BB143E 5D pop ebp
00BB143F C3 ret
=======================================================
int add(int c, int d){
00BB13C0 55 push ebp
00BB13C1 8B EC mov ebp,esp
00BB13C3 81 EC CC 00 00 00 sub esp,0CCh
----------------------------------------------------------------------------> 开辟栈帧
00BB13C9 53 push ebx
00BB13CA 56 push esi
00BB13CB 57 push edi
----------------------------------------------------------------------------> 保存现场
00BB13CC 8D BD 34 FF FF FF lea edi,[ebp-0CCh]
00BB13D2 B9 33 00 00 00 mov ecx,33h
00BB13D7 B8 CC CC CC CC mov eax,0CCCCCCCCh
00BB13DC F3 AB rep stos dword ptr es:[edi]
----------------------------------------------------------------------------> 初始化栈帧
int a = 3;
00BB13DE C7 45 F8 03 00 00 00 mov dword ptr [a],3
return c + d;
00BB13E5 8B 45 08 mov eax,dword ptr [c]
return c + d;
00BB13E8 03 45 0C add eax,dword ptr [d]
}
----------------------------------------------------------------------------> 处理函数内部逻辑
00BB13EB 5F pop edi
00BB13EC 5E pop esi
00BB13ED 5B pop ebx
----------------------------------------------------------------------------> 恢复现场
00BB13EE 8B E5 mov esp,ebp
00BB13F0 5D pop ebp
----------------------------------------------------------------------------> 恢复栈帧
00BB13F1 C3 ret
----------------------------------------------------------------------------> 平衡栈对call的调用
========================================================================
汇编地址/有效地址 | 栈内存空间 | 基础寄存器 | 栈帧所属函数 |
esi | esp | ||
edi | esp | ||
ebx | esp | ||
c | esp | ||
c | |||
c | |||
3 | |||
c | |||
ebp | esp/ebp | add() | |
return addr | esp | ||
1 | esp | ||
2 | esp | ||
esp | |||
ebp | main() |