// chapter1.4.2.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"#include <iostream>
int _tmain(int argc, _TCHAR* argv[]){ int sum = 0; for(int val = 1; val <= 10; ++val) { sum += val; } std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl; return 0;}
debug
od
004114B0 55 push ebp004114B1 8BEC mov ebp, esp004114B3 81EC D8000000 sub esp, 0D8004114B9 53 push ebx004114BA 56 push esi004114BB 57 push edi004114BC 8DBD 28FFFFFF lea edi, dword ptr [ebp-D8]004114C2 B9 36000000 mov ecx, 36004114C7 B8 CCCCCCCC mov eax, CCCCCCCC004114CC F3:AB rep stos dword ptr es:[edi]004114CE C745 F8 0000000>mov dword ptr [ebp-8], 0 ; sum=0004114D5 C745 EC 0100000>mov dword ptr [ebp-14], 1 ; val=1004114DC EB 09 jmp short 004114E7004114DE 8B45 EC mov eax, dword ptr [ebp-14] ; val->eax004114E1 83C0 01 add eax, 1 ; eax=eax+1004114E4 8945 EC mov dword ptr [ebp-14], eax ; eax->val004114E7 837D EC 0A cmp dword ptr [ebp-14], 0A ; val <= 10004114EB 7F 0B jg short 004114F8004114ED 8B45 F8 mov eax, dword ptr [ebp-8] ; sum->exa004114F0 0345 EC add eax, dword ptr [ebp-14] ; eax=sum+val004114F3 8945 F8 mov dword ptr [ebp-8], eax ; eax->sum004114F6 ^ EB E6 jmp short 004114DE004114F8 8BF4 mov esi, esp004114FA A1 08A34100 mov eax, dword ptr [<&MSVCP90D.std::>004114FF 50 push eax00411500 8BFC mov edi, esp00411502 8B4D F8 mov ecx, dword ptr [ebp-8]00411505 51 push ecx00411506 68 00784100 push 00417800 ; ASCII "Sum of 1 to 10 inclusive is "0041150B 8B15 04A34100 mov edx, dword ptr [<&MSVCP90D.std::>; MSVCP90D.std::cout00411511 52 push edx00411512 E8 47FCFFFF call 0041115E00411517 83C4 08 add esp, 80041151A 8BC8 mov ecx, eax0041151C FF15 00A34100 call dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<00411522 3BFC cmp edi, esp00411524 E8 85FCFFFF call 004111AE00411529 8BC8 mov ecx, eax0041152B FF15 FCA24100 call dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<00411531 3BF4 cmp esi, esp00411533 E8 76FCFFFF call 004111AE00411538 33C0 xor eax, eax0041153A 5F pop edi0041153B 5E pop esi0041153C 5B pop ebx0041153D 81C4 D8000000 add esp, 0D800411543 3BEC cmp ebp, esp00411545 E8 64FCFFFF call 004111AE0041154A 8BE5 mov esp, ebp0041154C 5D pop ebp0041154D C3 retn
ida
.text:004114B0.text:004114B0 ; =============== S U B R O U T I N E =======================================.text:004114B0.text:004114B0 ; Attributes: bp-based frame.text:004114B0.text:004114B0 _wmain proc near ; CODE XREF: j__wmainj.text:004114B0.text:004114B0 var_D8 = byte ptr -0D8h.text:004114B0 val = dword ptr -14h.text:004114B0 sum = dword ptr -8.text:004114B0.text:004114B0 push ebp.text:004114B1 mov ebp, esp.text:004114B3 sub esp, 0D8h.text:004114B9 push ebx.text:004114BA push esi.text:004114BB push edi.text:004114BC lea edi, [ebp+var_D8].text:004114C2 mov ecx, 36h.text:004114C7 mov eax, 0CCCCCCCCh.text:004114CC rep stosd.text:004114CE mov [ebp+sum], 0.text:004114D5 mov [ebp+val], 1.text:004114DC jmp short compare.text:004114DE ; ---------------------------------------------------------------------------.text:004114DE.text:004114DE addvalbyone: ; CODE XREF: _wmain+46j.text:004114DE mov eax, [ebp+val].text:004114E1 add eax, 1.text:004114E4 mov [ebp+val], eax.text:004114E7.text:004114E7 compare: ; CODE XREF: _wmain+2Cj.text:004114E7 cmp [ebp+val], 0Ah.text:004114EB jg short printresult.text:004114ED mov eax, [ebp+sum].text:004114F0 add eax, [ebp+val].text:004114F3 mov [ebp+sum], eax.text:004114F6 jmp short addvalbyone.text:004114F8 ; ---------------------------------------------------------------------------.text:004114F8.text:004114F8 printresult: ; CODE XREF: _wmain+3Bj.text:004114F8 mov esi, esp.text:004114FA 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:004114FF push eax.text:00411500 mov edi, esp.text:00411502 mov ecx, [ebp+sum].text:00411505 push ecx.text:00411506 push offset aSumOf1To10Incl ; "Sum of 1 to 10 inclusive is ".text:0041150B 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:00411511 push edx.text:00411512 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:00411517 add esp, 8.text:0041151A mov ecx, eax.text:0041151C 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:00411522 cmp edi, esp.text:00411524 call j___RTC_CheckEsp.text:00411529 mov ecx, eax.text:0041152B 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:00411531 cmp esi, esp.text:00411533 call j___RTC_CheckEsp.text:00411538 xor eax, eax.text:0041153A pop edi.text:0041153B pop esi.text:0041153C pop ebx.text:0041153D add esp, 0D8h.text:00411543 cmp ebp, esp.text:00411545 call j___RTC_CheckEsp.text:0041154A mov esp, ebp.text:0041154C pop ebp.text:0041154D retn.text:0041154D _wmain endp.text:0041154D.text:0041154D ; ---------------------------------------------------------------------------
release
od
00401000 /$ A1 38204000 mov eax, dword ptr [<&MSVCP90.std::e>00401005 |. 8B0D 44204000 mov ecx, dword ptr [<&MSVCP90.std::c>; MSVCP90.std::cout0040100B |. 50 push eax0040100C |. 6A 37 push 370040100E |. 51 push ecx0040100F |. E8 4C010000 call 0040116000401014 |. 83C4 04 add esp, 400401017 |. 8BC8 mov ecx, eax00401019 |. FF15 58204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<0040101F |. 8BC8 mov ecx, eax00401021 |. FF15 40204000 call dword ptr [<&MSVCP90.std::basic_>; MSVCP90.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<00401027 |. 33C0 xor eax, eax00401029 \. C3 retn
ida
.text:00401000 ; =============== S U B R O U T I N E =======================================.text:00401000.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 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:00401005 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:0040100B push eax.text:0040100C push 37h ; 55.text:0040100E push ecx.text:0040100F 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:00401014 add esp, 4.text:00401017 mov ecx, eax.text:00401019 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:0040101F mov ecx, eax.text:00401021 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:00401027 xor eax, eax.text:00401029 retn.text:00401029 _main endp.text:00401029.text:00401029 ; ---------------------------------------------------------------------------
转载于:https://www.cnblogs.com/nanshouyong326/archive/2010/06/20/1761374.html
