chapter1.4.1
// chapter1.4.1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
int _tmain(int argc, _TCHAR* argv[])
{
int sum=0,val=1;
while(val <=10)
{
sum+=val;
++val;
}
std::cout<<"Sum of 1 to 10 inclusive is "
<< sum<<std::endl;
return 0;
}
debug
od
004114B0 55 push ebp
004114B1 8BEC mov ebp, esp
004114B3 81EC D8000000 sub esp, 0D8
004114B9 53 push ebx
004114BA 56 push esi
004114BB 57 push edi
004114BC 8DBD 28FFFFFF lea edi, dword ptr [ebp-D8]
004114C2 B9 36000000 mov ecx, 36
004114C7 B8 CCCCCCCC mov eax, CCCCCCCC
004114CC F3:AB rep stos dword ptr es:[edi]
004114CE C745 F8 0000000>mov dword ptr [ebp-8], 0 ; sum=0
004114D5 C745 EC 0100000>mov dword ptr [ebp-14], 1 ; val=1
004114DC 837D EC 0A cmp dword ptr [ebp-14], 0A
004114E0 7F 14 jg short 004114F6 ; 大于退出
004114E2 8B45 F8 mov eax, dword ptr [ebp-8]
004114E5 0345 EC add eax, dword ptr [ebp-14] ; sum+=val
004114E8 8945 F8 mov dword ptr [ebp-8], eax
004114EB 8B45 EC mov eax, dword ptr [ebp-14]
004114EE 83C0 01 add eax, 1
004114F1 8945 EC mov dword ptr [ebp-14], eax
004114F4 ^ EB E6 jmp short 004114DC
004114F6 8BF4 mov esi, esp
004114F8 A1 08A34100 mov eax, dword ptr [<&MSVCP90D.std::>
004114FD 50 push eax
004114FE 8BFC mov edi, esp
00411500 8B4D F8 mov ecx, dword ptr [ebp-8] ; sum
00411503 51 push ecx
00411504 68 00784100 push 00417800 ; ASCII "Sum of 1 to 10 inclusive is "
00411509 8B15 04A34100 mov edx, dword ptr [<&MSVCP90D.std::>; MSVCP90D.std::cout
0041150F 52 push edx
00411510 E8 49FCFFFF call 0041115E
00411515 83C4 08 add esp, 8
00411518 8BC8 mov ecx, eax
0041151A FF15 00A34100 call dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
00411520 3BFC cmp edi, esp
00411522 E8 87FCFFFF call 004111AE
00411527 8BC8 mov ecx, eax
00411529 FF15 FCA24100 call dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
0041152F 3BF4 cmp esi, esp
00411531 E8 78FCFFFF call 004111AE
00411536 33C0 xor eax, eax ; 返回值
00411538 5F pop edi
00411539 5E pop esi
0041153A 5B pop ebx
0041153B 81C4 D8000000 add esp, 0D8
00411541 3BEC cmp ebp, esp
00411543 E8 66FCFFFF call 004111AE
00411548 8BE5 mov esp, ebp
0041154A 5D pop ebp
0041154B C3 retn
ida
.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
.text:004114DC addinwhile: ; CODE XREF: _wmain+44j
.text:004114DC cmp [ebp+val], 0Ah
.text:004114E0 jg short printresult
.text:004114E2 mov eax, [ebp+sum]
.text:004114E5 add eax, [ebp+val]
.text:004114E8 mov [ebp+sum], eax
.text:004114EB mov eax, [ebp+val]
.text:004114EE add eax, 1
.text:004114F1 mov [ebp+val], eax
.text:004114F4 jmp short addinwhile
.text:004114F6 ; ---------------------------------------------------------------------------
.text:004114F6
.text:004114F6 printresult: ; CODE XREF: _wmain+30j
.text:004114F6 mov esi, esp
.text:004114F8 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:004114FD push eax
.text:004114FE mov edi, esp
.text:00411500 mov ecx, [ebp+sum]
.text:00411503 push ecx
.text:00411504 push offset aSumOf1To10Incl ; "Sum of 1 to 10 inclusive is "
.text:00411509 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:0041150F push edx
.text:00411510 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:00411515 add esp, 8
.text:00411518 mov ecx, eax
.text:0041151A 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:00411520 cmp edi, esp
.text:00411522 call j___RTC_CheckEsp
.text:00411527 mov ecx, eax
.text:00411529 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:0041152F cmp esi, esp
.text:00411531 call j___RTC_CheckEsp
.text:00411536 xor eax, eax
.text:00411538 pop edi
.text:00411539 pop esi
.text:0041153A pop ebx
.text:0041153B add esp, 0D8h
.text:00411541 cmp ebp, esp
.text:00411543 call j___RTC_CheckEsp
.text:00411548 mov esp, ebp
.text:0041154A pop ebp
.text:0041154B retn
.text:0041154B _wmain endp
.text:0041154B
.text:0041154B ; ---------------------------------------------------------------------------
release
od