chapter1.4.2

// 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    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    EB 09           jmp     short 004114E7
004114DE    8B45 EC         mov     eax, dword ptr [ebp-14]          ; val->eax
004114E1    83C0 01         add     eax, 1                           ; eax=eax+1
004114E4    8945 EC         mov     dword ptr [ebp-14], eax          ; eax->val
004114E7    837D EC 0A      cmp     dword ptr [ebp-14], 0A           ; val <= 10
004114EB    7F 0B           jg      short 004114F8
004114ED    8B45 F8         mov     eax, dword ptr [ebp-8]           ; sum->exa
004114F0    0345 EC         add     eax, dword ptr [ebp-14]          ; eax=sum+val
004114F3    8945 F8         mov     dword ptr [ebp-8], eax           ; eax->sum
004114F6  ^ EB E6           jmp     short 004114DE
004114F8    8BF4            mov     esi, esp
004114FA    A1 08A34100     mov     eax, dword ptr [<&MSVCP90D.std::>
004114FF    50              push    eax
00411500    8BFC            mov     edi, esp
00411502    8B4D F8         mov     ecx, dword ptr [ebp-8]
00411505    51              push    ecx
00411506    68 00784100     push    00417800                         ; ASCII "Sum of 1 to 10 inclusive is "
0041150B    8B15 04A34100   mov     edx, dword ptr [<&MSVCP90D.std::>; MSVCP90D.std::cout
00411511    52              push    edx
00411512    E8 47FCFFFF     call    0041115E
00411517    83C4 08         add     esp, 8
0041151A    8BC8            mov     ecx, eax
0041151C    FF15 00A34100   call    dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
00411522    3BFC            cmp     edi, esp
00411524    E8 85FCFFFF     call    004111AE
00411529    8BC8            mov     ecx, eax
0041152B    FF15 FCA24100   call    dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
00411531    3BF4            cmp     esi, esp
00411533    E8 76FCFFFF     call    004111AE
00411538    33C0            xor     eax, eax
0041153A    5F              pop     edi
0041153B    5E              pop     esi
0041153C    5B              pop     ebx
0041153D    81C4 D8000000   add     esp, 0D8
00411543    3BEC            cmp     ebp, esp
00411545    E8 64FCFFFF     call    004111AE
0041154A    8BE5            mov     esp, ebp
0041154C    5D              pop     ebp
0041154D    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::cout
0040100B  |.  50            push    eax
0040100C  |.  6A 37         push    37
0040100E  |.  51            push    ecx
0040100F  |.  E8 4C010000   call    00401160
00401014  |.  83C4 04       add     esp, 4
00401017  |.  8BC8          mov     ecx, eax
00401019  |.  FF15 58204000 call    dword ptr [<&MSVCP90.std::basic_>;  MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<
0040101F  |.  8BC8          mov     ecx, eax
00401021  |.  FF15 40204000 call    dword ptr [<&MSVCP90.std::basic_>;  MSVCP90.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
00401027  |.  33C0          xor     eax, eax
00401029  \.  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 ; ---------------------------------------------------------------------------

posted @ 2010-06-20 14:05  南守拥  阅读(230)  评论(0编辑  收藏  举报