chapter1.2
// chapter1.2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<"Enter two numbers:"<<std::endl;
int v1,v2;
std::cin>>v1>>v2;
std::cout<<"The sum of "<<v1<<" and " <<v2 <<" is "<<v1+v2<<std::endl;
return 0;
}
debug
od
00414160 55 push ebp
00414161 8BEC mov ebp, esp
00414163 81EC DC000000 sub esp, 0DC
00414169 53 push ebx
0041416A 56 push esi
0041416B 57 push edi
0041416C 8DBD 24FFFFFF lea edi, dword ptr [ebp-DC]
00414172 B9 37000000 mov ecx, 37
00414177 B8 CCCCCCCC mov eax, CCCCCCCC
0041417C F3:AB rep stos dword ptr es:[edi]
0041417E 8BF4 mov esi, esp
00414180 A1 18A34100 mov eax, dword ptr [<&MSVCP90D.std::endl>]
00414185 50 push eax
00414186 68 20784100 push 00417820 ; ASCII "Enter two numbers:"
0041418B 8B0D 14A34100 mov ecx, dword ptr [<&MSVCP90D.std::cout>] ; MSVCP90D.std::cout
00414191 51 push ecx
00414192 E8 CCCFFFFF call 00411163
00414197 83C4 08 add esp, 8
0041419A 8BC8 mov ecx, eax
0041419C FF15 10A34100 call dword ptr [<&MSVCP90D.std::basic_ostream<>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
004141A2 3BF4 cmp esi, esp
004141A4 E8 0AD0FFFF call 004111B3
004141A9 8BF4 mov esi, esp
004141AB 8D45 EC lea eax, dword ptr [ebp-14]
004141AE 50 push eax
004141AF 8BFC mov edi, esp
004141B1 8D4D F8 lea ecx, dword ptr [ebp-8]
004141B4 51 push ecx
004141B5 8B0D 0CA34100 mov ecx, dword ptr [<&MSVCP90D.std::cin>] ; MSVCP90D.std::cin
004141BB FF15 08A34100 call dword ptr [<&MSVCP90D.std::basic_istream<>; MSVCP90D.std::basic_istream<char,std::char_traits<char> >::operator>>
004141C1 3BFC cmp edi, esp
004141C3 E8 EBCFFFFF call 004111B3
004141C8 8BC8 mov ecx, eax
004141CA FF15 08A34100 call dword ptr [<&MSVCP90D.std::basic_istream<>; MSVCP90D.std::basic_istream<char,std::char_traits<char> >::operator>>
004141D0 3BF4 cmp esi, esp
004141D2 E8 DCCFFFFF call 004111B3
004141D7 8BF4 mov esi, esp
004141D9 A1 18A34100 mov eax, dword ptr [<&MSVCP90D.std::endl>]
004141DE 50 push eax
004141DF 8B4D F8 mov ecx, dword ptr [ebp-8] ; v1
004141E2 034D EC add ecx, dword ptr [ebp-14] ; v2+v1
004141E5 8BFC mov edi, esp
004141E7 51 push ecx
004141E8 68 18784100 push 00417818 ; ASCII " is "
004141ED 8BDC mov ebx, esp
004141EF 8B55 EC mov edx, dword ptr [ebp-14]
004141F2 52 push edx
004141F3 68 10784100 push 00417810 ; ASCII " and "
004141F8 8BC4 mov eax, esp
004141FA 8B4D F8 mov ecx, dword ptr [ebp-8]
004141FD 51 push ecx
004141FE 68 00784100 push 00417800 ; ASCII "The sum of "
00414203 8B15 14A34100 mov edx, dword ptr [<&MSVCP90D.std::cout>] ; MSVCP90D.std::cout
00414209 52 push edx
0041420A 8985 24FFFFFF mov dword ptr [ebp-DC], eax
00414210 E8 4ECFFFFF call 00411163
00414215 83C4 08 add esp, 8
00414218 8BC8 mov ecx, eax
0041421A FF15 04A34100 call dword ptr [<&MSVCP90D.std::basic_ostream<>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
00414220 8B8D 24FFFFFF mov ecx, dword ptr [ebp-DC]
00414226 3BCC cmp ecx, esp
00414228 E8 86CFFFFF call 004111B3
0041422D 50 push eax
0041422E E8 30CFFFFF call 00411163
00414233 83C4 08 add esp, 8
00414236 8BC8 mov ecx, eax
00414238 FF15 04A34100 call dword ptr [<&MSVCP90D.std::basic_ostream<>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
0041423E 3BDC cmp ebx, esp
00414240 E8 6ECFFFFF call 004111B3
00414245 50 push eax
00414246 E8 18CFFFFF call 00411163
0041424B 83C4 08 add esp, 8
0041424E 8BC8 mov ecx, eax
00414250 FF15 04A34100 call dword ptr [<&MSVCP90D.std::basic_ostream<>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
00414256 3BFC cmp edi, esp
00414258 E8 56CFFFFF call 004111B3
0041425D 8BC8 mov ecx, eax
0041425F FF15 10A34100 call dword ptr [<&MSVCP90D.std::basic_ostream<>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
00414265 3BF4 cmp esi, esp
00414267 E8 47CFFFFF call 004111B3
0041426C 33C0 xor eax, eax ; 返回0
0041426E 52 push edx
0041426F 8BCD mov ecx, ebp
00414271 50 push eax
00414272 8D15 94424100 lea edx, dword ptr [414294]
00414278 E8 32CEFFFF call 004110AF
0041427D 58 pop eax
0041427E 5A pop edx
0041427F 5F pop edi
00414280 5E pop esi
00414281 5B pop ebx
00414282 81C4 DC000000 add esp, 0DC
00414288 3BEC cmp ebp, esp
0041428A E8 24CFFFFF call 004111B3
0041428F 8BE5 mov esp, ebp
00414291 5D pop ebp
00414292 C3 retn
ida
.text:00414160 ; =============== S U B R O U T I N E =======================================
.text:00414160
.text:00414160 ; Attributes: bp-based frame
.text:00414160
.text:00414160 _wmain proc near ; CODE XREF: j__wmainj
.text:00414160
.text:00414160 var_DC = dword ptr -0DCh
.text:00414160 v2 = dword ptr -14h
.text:00414160 v1 = dword ptr -8
.text:00414160
.text:00414160 push ebp
.text:00414161 mov ebp, esp
.text:00414163 sub esp, 0DCh
.text:00414169 push ebx
.text:0041416A push esi
.text:0041416B push edi
.text:0041416C lea edi, [ebp+var_DC]
.text:00414172 mov ecx, 37h
.text:00414177 mov eax, 0CCCCCCCCh
.text:0041417C rep stosd
.text:0041417E mov esi, esp
.text:00414180 mov eax, ds:__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z ; std::endl(std::basic_ostream<char,std::char_traits<char>> &)
.text:00414185 push eax
.text:00414186 push offset aEnterTwoNumber ; "Enter two numbers:"
.text:0041418B mov ecx, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:00414191 push ecx
.text:00414192 call j_??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00414197 add esp, 8
.text:0041419A mov ecx, eax
.text:0041419C call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(std::basic_ostream<char,std::char_traits<char>> & (*)(std::basic_ostream<char,std::char_traits<char>> &))
.text:004141A2 cmp esi, esp
.text:004141A4 call j___RTC_CheckEsp
.text:004141A9 mov esi, esp
.text:004141AB lea eax, [ebp+v2]
.text:004141AE push eax
.text:004141AF mov edi, esp
.text:004141B1 lea ecx, [ebp+v1]
.text:004141B4 push ecx
.text:004141B5 mov ecx, ds:__imp_?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A ; std::basic_istream<char,std::char_traits<char>> std::cin
.text:004141BB call ds:__imp_??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z ; std::basic_istream<char,std::char_traits<char>>::operator>>(int &)
.text:004141C1 cmp edi, esp
.text:004141C3 call j___RTC_CheckEsp
.text:004141C8 mov ecx, eax
.text:004141CA call ds:__imp_??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z ; std::basic_istream<char,std::char_traits<char>>::operator>>(int &)
.text:004141D0 cmp esi, esp
.text:004141D2 call j___RTC_CheckEsp
.text:004141D7 mov esi, esp
.text:004141D9 mov eax, ds:__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z ; std::endl(std::basic_ostream<char,std::char_traits<char>> &)
.text:004141DE push eax
.text:004141DF mov ecx, [ebp+v1]
.text:004141E2 add ecx, [ebp+v2]
.text:004141E5 mov edi, esp
.text:004141E7 push ecx ; v1+v2 push
.text:004141E8 push offset aIs ; " is "
.text:004141ED mov ebx, esp
.text:004141EF mov edx, [ebp+v2]
.text:004141F2 push edx
.text:004141F3 push offset aAnd ; " and "
.text:004141F8 mov eax, esp
.text:004141FA mov ecx, [ebp+v1]
.text:004141FD push ecx
.text:004141FE push offset aTheSumOf ; "The sum of "
.text:00414203 mov edx, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:00414209 push edx
.text:0041420A mov [ebp+var_DC], eax
.text:00414210 call j_??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00414215 add esp, 8
.text:00414218 mov ecx, eax
.text:0041421A call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:00414220 mov ecx, [ebp+var_DC]
.text:00414226 cmp ecx, esp
.text:00414228 call j___RTC_CheckEsp
.text:0041422D push eax
.text:0041422E call j_??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00414233 add esp, 8
.text:00414236 mov ecx, eax
.text:00414238 call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:0041423E cmp ebx, esp
.text:00414240 call j___RTC_CheckEsp
.text:00414245 push eax
.text:00414246 call j_??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:0041424B add esp, 8
.text:0041424E mov ecx, eax
.text:00414250 call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:00414256 cmp edi, esp
.text:00414258 call j___RTC_CheckEsp
.text:0041425D mov ecx, eax
.text:0041425F call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(std::basic_ostream<char,std::char_traits<char>> & (*)(std::basic_ostream<char,std::char_traits<char>> &))
.text:00414265 cmp esi, esp
.text:00414267 call j___RTC_CheckEsp
.text:0041426C xor eax, eax
.text:0041426E push edx
.text:0041426F mov ecx, ebp
.text:00414271 push eax
.text:00414272 lea edx, dword_414294
.text:00414278 call j_@_RTC_CheckStackVars@8 ; _RTC_CheckStackVars(x,x)
.text:0041427D pop eax
.text:0041427E pop edx
.text:0041427F pop edi
.text:00414280 pop esi
.text:00414281 pop ebx
.text:00414282 add esp, 0DCh
.text:00414288 cmp ebp, esp
.text:0041428A call j___RTC_CheckEsp
.text:0041428F mov esp, ebp
.text:00414291 pop ebp
.text:00414292 retn
.text:00414292 _wmain endp
.text:00414292
release
od
00401000 /$ 55 push ebp
00401001 |. 8BEC mov ebp, esp
00401003 |. 83E4 F8 and esp, FFFFFFF8
00401006 |. A1 3C204000 mov eax, dword ptr [<&MSVCP90.std::e>
0040100B |. 83EC 08 sub esp, 8 ; 分局部变量V1和V2
0040100E |. 50 push eax ; MSVCP90.std::endl
0040100F |. 51 push ecx
00401010 |. 8B0D 5C204000 mov ecx, dword ptr [<&MSVCP90.std::c>; MSVCP90.std::cout
00401016 |. 68 34214000 push 00402134 ; ASCII "Enter two numbers:"
0040101B |. 51 push ecx
0040101C |. E8 CF010000 call 004011F0
00401021 |. 83C4 0C add esp, 0C
00401024 |. 8BC8 mov ecx, eax
00401026 |. FF15 40204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
0040102C |. 8B0D 6C204000 mov ecx, dword ptr [<&MSVCP90.std::c>; MSVCP90.std::cin
00401032 |. 8D1424 lea edx, dword ptr [esp] ; 取V2地址
00401035 |. 52 push edx
00401036 |. 8D4424 08 lea eax, dword ptr [esp+8] ; 取V1地址
0040103A |. 50 push eax
0040103B |. FF15 4C204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_istream<char,std::char_traits<char> >::operator>>
00401041 |. 8BC8 mov ecx, eax
00401043 |. FF15 4C204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_istream<char,std::char_traits<char> >::operator>>
00401049 |. 8B0D 3C204000 mov ecx, dword ptr [<&MSVCP90.std::e>; MSVCP90.std::endl
0040104F |. 8B0424 mov eax, dword ptr [esp] ; v2
00401052 |. 51 push ecx ; endl
00401053 |. 8B4C24 08 mov ecx, dword ptr [esp+8] ; v1
00401057 |. 8D1408 lea edx, dword ptr [eax+ecx] ; v1+v2
0040105A |. 52 push edx
0040105B |. 68 48214000 push 00402148 ; ASCII " is "
00401060 |. 50 push eax
00401061 |. A1 5C204000 mov eax, dword ptr [<&MSVCP90.std::c>
00401066 |. 68 50214000 push 00402150 ; ASCII " and "
0040106B |. 51 push ecx
0040106C |. 68 58214000 push 00402158 ; ASCII "The sum of "
00401071 |. 50 push eax
00401072 |. E8 79010000 call 004011F0
00401077 |. 83C4 08 add esp, 8
0040107A |. 8BC8 mov ecx, eax
0040107C |. FF15 44204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<
00401082 |. 50 push eax
00401083 |. E8 68010000 call 004011F0
00401088 |. 83C4 08 add esp, 8
0040108B |. 8BC8 mov ecx, eax
0040108D |. FF15 44204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<
00401093 |. 50 push eax
00401094 |. E8 57010000 call 004011F0
00401099 |. 83C4 08 add esp, 8
0040109C |. 8BC8 mov ecx, eax
0040109E |. FF15 44204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<
004010A4 |. 8BC8 mov ecx, eax
004010A6 |. FF15 40204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
004010AC |. 33C0 xor eax, eax
004010AE |. 8BE5 mov esp, ebp
004010B0 |. 5D pop ebp
004010B1 \. C3 retn
ida
.text:00401000 ; =============== S U B R O U T I N E =======================================
.text:00401000
.text:00401000 ; Attributes: bp-based frame
.text:00401000
.text:00401000 ; int __cdecl main(int argc, const char **argv, const char *envp)
.text:00401000 _main proc near ; CODE XREF: ___tmainCRTStartup+10Ap
.text:00401000
.text:00401000 var_10 = dword ptr -10h
.text:00401000 var_C = dword ptr -0Ch
.text:00401000 v2 = byte ptr -8
.text:00401000 v1 = byte ptr -4
.text:00401000 argc = dword ptr 8
.text:00401000 argv = dword ptr 0Ch
.text:00401000 envp = dword ptr 10h
.text:00401000
.text:00401000 push ebp
.text:00401001 mov ebp, esp
.text:00401003 and esp, 0FFFFFFF8h
.text:00401006 mov eax, ds:__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z ; std::endl(std::basic_ostream<char,std::char_traits<char>> &)
.text:0040100B sub esp, 8 ; 分局部变量V1和V2
.text:0040100E push eax ; endl
.text:0040100F push ecx
.text:00401010 mov ecx, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:00401016 push offset aEnterTwoNumber ; "Enter two numbers:"
.text:0040101B push ecx
.text:0040101C call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00401021 add esp, 0Ch ; 平衡
.text:00401024 mov ecx, eax
.text:00401026 call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(std::basic_ostream<char,std::char_traits<char>> & (*)(std::basic_ostream<char,std::char_traits<char>> &))
.text:0040102C mov ecx, ds:__imp_?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A ; std::basic_istream<char,std::char_traits<char>> std::cin
.text:00401032 lea edx, [esp+8+v2] ; v2
.text:00401035 push edx
.text:00401036 lea eax, [esp+0Ch+v1] ; v1
.text:0040103A push eax
.text:0040103B call ds:__imp_??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z ; std::basic_istream<char,std::char_traits<char>>::operator>>(int &)
.text:00401041 mov ecx, eax
.text:00401043 call ds:__imp_??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z ; std::basic_istream<char,std::char_traits<char>>::operator>>(int &)
.text:00401049 mov ecx, ds:__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z ; std::endl(std::basic_ostream<char,std::char_traits<char>> &)
.text:0040104F mov eax, [esp+10h+var_10]
.text:00401052 push ecx
.text:00401053 mov ecx, [esp+14h+var_C]
.text:00401057 lea edx, [eax+ecx]
.text:0040105A push edx
.text:0040105B push offset aIs ; " is "
.text:00401060 push eax
.text:00401061 mov eax, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:00401066 push offset aAnd ; " and "
.text:0040106B push ecx
.text:0040106C push offset aTheSumOf ; "The sum of "
.text:00401071 push eax
.text:00401072 call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00401077 add esp, 8
.text:0040107A mov ecx, eax
.text:0040107C call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:00401082 push eax
.text:00401083 call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00401088 add esp, 8
.text:0040108B mov ecx, eax
.text:0040108D call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:00401093 push eax
.text:00401094 call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:00401099 add esp, 8
.text:0040109C mov ecx, eax
.text:0040109E call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(int)
.text:004010A4 mov ecx, eax
.text:004010A6 call ds:__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z ; std::basic_ostream<char,std::char_traits<char>>::operator<<(std::basic_ostream<char,std::char_traits<char>> & (*)(std::basic_ostream<char,std::char_traits<char>> &))
.text:004010AC xor eax, eax
.text:004010AE mov esp, ebp
.text:004010B0 pop ebp
.text:004010B1 retn
.text:004010B1 _main endp
.text:004010B1
.text:004010B1 ; ---------------------------------------------------------------------------