答复
每个编译器使实现不一样。。你说的这个市intel C++ 的实现方法。
int _tmain(int argc, _TCHAR* argv[])
{
0040105C push ebp
0040105D mov ebp,esp
0040105F sub esp,3
00401062 and esp,0FFFFFFF8h
00401065 add esp,4
00401068 sub esp,38h
0040106B mov eax,dword ptr [___security_cookie (403000h)]
00401070 mov dword ptr [ebp-4],eax
wchar_t buf[16];
这是在Intel C++ 10的优化下 and esp,FFFFFFF0 可见这句。
可以推测是结构堆对齐
00401000 T>/$ 55 push ebp
00401001 |. 8BEC mov ebp,esp
00401003 |. 83E4 F0 and esp,FFFFFFF0
00401006 |. 83EC 20 sub esp,20
00401009 |. 6A 03 push 3
0040100B |. E8 D4000000 call TEST_2.004010E4
00401010 |. 8D4424 04 lea eax,dword ptr ss:[esp+4]
00401014 |. 68 2E104000 push TEST_2.0040102E ; /<%d> = 40102E (4198446.)
00401019 |. 68 3C204000 push TEST_2.0040203C ; |Format = "%d"
0040101E |. 50 push eax ; |s
0040101F |. FF15 08204000 call dword ptr ds:[<&USER32.wsprintfW>] ; \wsprintfW
00401025 |. 83C4 10 add esp,10
00401028 |. 33C0 xor eax,eax
0040102A |. 8BE5 mov esp,ebp
0040102C |. 5D pop ebp
0040102D \. C3 retn
关闭优化下
0040105C T>/$ 55 push ebp
0040105D |. 8BEC mov ebp,esp
0040105F |. 83EC 03 sub esp,3
00401062 |. 83E4 F8 and esp,FFFFFFF8
00401065 |. 83C4 04 add esp,4
00401068 |. 83EC 2C sub esp,2C
0040106B |. A1 00204000 mov eax,dword ptr ds:[<&USER32.wsprintfW>]
00401070 |. 83C4 00 add esp,0
00401073 |. 8D55 E0 lea edx,[local.8] ; |
00401076 |. 891424 mov dword ptr ss:[esp],edx ; |
00401079 |. C74424 04 00304000 mov dword ptr ss:[esp+4],TEST_2.00403000 ; |UNICODE "%d"
00401081 |. C74424 08 00104000 mov dword ptr ss:[esp+8],TEST_2.00401000 ; |
00401089 |. FFD0 call eax ; \wsprintfW
0040108B |. 83C4 0C add esp,0C
0040108E |. 33C0 xor eax,eax
00401090 |. C9 leave
00401091 \. C3 retn
确实Intel C++的优化达到了前所未有的高度。。令人叹为观止。
