我们在分析问题的时候经常会需要查看进程的栈和帧中的值,下面我们就用一个简单的例子来分析一下这个过程。
源代码:
#include <iostream>
int add(int a, int b)
{
return a + b;
}
int main()
{
int a, b;
a = 3;
b = 4;
int ret = add(a, b);
std::cout << "Result:"<<ret<<"\t\n";
}
生成的汇编代码:
main 函数的汇编代码
10 004c1000 55 push ebp
10 004c1001 8bec mov ebp,esp
10 004c1003 83ec0c sub esp,0Ch
12 004c1006 c745f803000000 mov dword ptr [ebp-8],3
13 004c100d c745fc04000000 mov dword ptr [ebp-4],4
14 004c1014 8b45fc mov eax,dword ptr [ebp-4]
14 004c1017 50 push eax
14 004c1018 8b4df8 mov ecx,dword ptr [ebp-8]
14 004c101b 51 push ecx
14 004c101c e83f000000 call statckTest!add (004c1060)
14 004c1021 83c408 add esp,8
14 004c1024 8945f4 mov dword ptr [ebp-0Ch],eax
15 004c1027 6840314c00 push offset statckTest!GS_ExceptionPointers+0x8 (004c3140)
15 004c102c 8b55f4 mov edx,dword ptr [ebp-0Ch]
15 004c102f 52 push edx
15 004c1030 6844314c00 push offset statckTest!std::_Fake_alloc+0x1 (004c3144)
15 004c1035 a16c304c00 mov eax,dword ptr [statckTest!_imp_?coutstd (004c306c)]
15 004c103a 50 push eax
15 004c103b e8e0020000 call statckTest!std::operator<<<std::char_traits<char> > (004c1320)
15 004c1040 83c408 add esp,8
15 004c1043 8bc8 mov ecx,eax
15 004c1045 ff1540304c00 call dword ptr [statckTest!_imp_??6?$basic_ostreamDU?$char_traitsDstdstdQAEAAV01HZ (004c3040)]
15 004c104b 50 push eax
15 004c104c e8cf020000 call statckTest!std::operator<<<std::char_traits<char> > (004c1320)
15 004c1051 83c408 add esp,8
16 004c1054 33c0 xor eax,eax
16 004c1056 8be5 mov esp,ebp
16 004c1058