chapter1.4.4

 

// chapter1.4.4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
 int sum = 0, value;
 while(std::cin>>value)
 {
  sum+=value;
 }
 std::cout<<"Sum is "
  <<sum<<std::endl;
 return 0;
}

 

 

debug

od

 

004114C0    55              push    ebp
004114C1    8BEC            mov     ebp, esp
004114C3    81EC E4000000   sub     esp, 0E4
004114C9    53              push    ebx
004114CA    56              push    esi
004114CB    57              push    edi
004114CC    8DBD 1CFFFFFF   lea     edi, dword ptr [ebp-E4]
004114D2    B9 39000000     mov     ecx, 39
004114D7    B8 CCCCCCCC     mov     eax, CCCCCCCC
004114DC    F3:AB           rep     stos dword ptr es:[edi]
004114DE    C745 F8 0000000>mov     dword ptr [ebp-8], 0
004114E5    8BF4            mov     esi, esp
004114E7    8D45 EC         lea     eax, dword ptr [ebp-14]
004114EA    50              push    eax
004114EB    8B0D 24A34100   mov     ecx, dword ptr [<&MSVCP90D.std::>; MSVCP90D.std::cin
004114F1    FF15 20A34100   call    dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_istream<char,std::char_traits<char> >::operator>>
004114F7    3BF4            cmp     esi, esp
004114F9    E8 BAFCFFFF     call    004111B8
004114FE    8985 20FFFFFF   mov     dword ptr [ebp-E0], eax
00411504    8B8D 20FFFFFF   mov     ecx, dword ptr [ebp-E0]
0041150A    8B11            mov     edx, dword ptr [ecx]
0041150C    8B8D 20FFFFFF   mov     ecx, dword ptr [ebp-E0]
00411512    034A 04         add     ecx, dword ptr [edx+4]
00411515    8BF4            mov     esi, esp
00411517    FF15 1CA34100   call    dword ptr [<&MSVCP90D.std::ios_b>; MSVCP90D.std::ios_base::operator void *
0041151D    3BF4            cmp     esi, esp
0041151F    E8 94FCFFFF     call    004111B8
00411524    85C0            test    eax, eax                         ; 输入是否结束
00411526    74 0B           je      short 00411533
00411528    8B45 F8         mov     eax, dword ptr [ebp-8]           ; sum
0041152B    0345 EC         add     eax, dword ptr [ebp-14]          ; sum+=value
0041152E    8945 F8         mov     dword ptr [ebp-8], eax
00411531  ^ EB B2           jmp     short 004114E5
00411533    8BF4            mov     esi, esp
00411535    A1 18A34100     mov     eax, dword ptr [<&MSVCP90D.std::>
0041153A    50              push    eax
0041153B    8BFC            mov     edi, esp
0041153D    8B4D F8         mov     ecx, dword ptr [ebp-8]
00411540    51              push    ecx
00411541    68 00784100     push    00417800                         ; ASCII "Sum is "
00411546    8B15 14A34100   mov     edx, dword ptr [<&MSVCP90D.std::>; MSVCP90D.std::cout
0041154C    52              push    edx
0041154D    E8 11FCFFFF     call    00411163
00411552    83C4 08         add     esp, 8
00411555    8BC8            mov     ecx, eax
00411557    FF15 10A34100   call    dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<char,std::char_traits<char> >::operator<<
0041155D    3BFC            cmp     edi, esp
0041155F    E8 54FCFFFF     call    004111B8
00411564    8BC8            mov     ecx, eax
00411566    FF15 0CA34100   call    dword ptr [<&MSVCP90D.std::basic>; MSVCP90D.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
0041156C    3BF4            cmp     esi, esp
0041156E    E8 45FCFFFF     call    004111B8
00411573    33C0            xor     eax, eax
00411575    52              push    edx
00411576    8BCD            mov     ecx, ebp
00411578    50              push    eax
00411579    8D15 9C154100   lea     edx, dword ptr [41159C]
0041157F    E8 2BFBFFFF     call    004110AF
00411584    58              pop     eax
00411585    5A              pop     edx
00411586    5F              pop     edi
00411587    5E              pop     esi
00411588    5B              pop     ebx
00411589    81C4 E4000000   add     esp, 0E4
0041158F    3BEC            cmp     ebp, esp
00411591    E8 22FCFFFF     call    004111B8
00411596    8BE5            mov     esp, ebp
00411598    5D              pop     ebp
00411599    C3              retn

 ida

.text:004114C0
.text:004114C0 ; =============== S U B R O U T I N E =======================================
.text:004114C0
.text:004114C0 ; Attributes: bp-based frame
.text:004114C0
.text:004114C0 _wmain          proc near               ; CODE XREF: j__wmainj
.text:004114C0
.text:004114C0 var_E4          = byte ptr -0E4h
.text:004114C0 cin             = dword ptr -0E0h
.text:004114C0 value           = dword ptr -14h
.text:004114C0 sum             = dword ptr -8
.text:004114C0
.text:004114C0                 push    ebp
.text:004114C1                 mov     ebp, esp
.text:004114C3                 sub     esp, 0E4h
.text:004114C9                 push    ebx
.text:004114CA                 push    esi
.text:004114CB                 push    edi
.text:004114CC                 lea     edi, [ebp+var_E4]
.text:004114D2                 mov     ecx, 39h
.text:004114D7                 mov     eax, 0CCCCCCCCh
.text:004114DC                 rep stosd
.text:004114DE                 mov     [ebp+sum], 0
.text:004114E5
.text:004114E5 loc_4114E5:                             ; CODE XREF: _wmain+71j
.text:004114E5                 mov     esi, esp
.text:004114E7                 lea     eax, [ebp+value]
.text:004114EA                 push    eax
.text:004114EB                 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:004114F1                 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:004114F7                 cmp     esi, esp
.text:004114F9                 call    j___RTC_CheckEsp
.text:004114FE                 mov     [ebp+cin], eax
.text:00411504                 mov     ecx, [ebp+cin]
.text:0041150A                 mov     edx, [ecx]
.text:0041150C                 mov     ecx, [ebp+cin]
.text:00411512                 add     ecx, [edx+4]
.text:00411515                 mov     esi, esp
.text:00411517                 call    ds:__imp_??Bios_base@std@@QBEPAXXZ ; std::ios_base::operator void *(void)
.text:0041151D                 cmp     esi, esp
.text:0041151F                 call    j___RTC_CheckEsp
.text:00411524                 test    eax, eax
.text:00411526                 jz      short loc_411533
.text:00411528                 mov     eax, [ebp+sum]
.text:0041152B                 add     eax, [ebp+value]
.text:0041152E                 mov     [ebp+sum], eax
.text:00411531                 jmp     short loc_4114E5
.text:00411533 ; ---------------------------------------------------------------------------
.text:00411533
.text:00411533 loc_411533:                             ; CODE XREF: _wmain+66j
.text:00411533                 mov     esi, esp
.text:00411535                 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:0041153A                 push    eax
.text:0041153B                 mov     edi, esp
.text:0041153D                 mov     ecx, [ebp+sum]
.text:00411540                 push    ecx
.text:00411541                 push    offset aSumIs   ; "Sum is "
.text:00411546                 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:0041154C                 push    edx
.text:0041154D                 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:00411552                 add     esp, 8
.text:00411555                 mov     ecx, eax
.text:00411557                 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:0041155D                 cmp     edi, esp
.text:0041155F                 call    j___RTC_CheckEsp
.text:00411564                 mov     ecx, eax
.text:00411566                 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:0041156C                 cmp     esi, esp
.text:0041156E                 call    j___RTC_CheckEsp
.text:00411573                 xor     eax, eax
.text:00411575                 push    edx
.text:00411576                 mov     ecx, ebp
.text:00411578                 push    eax
.text:00411579                 lea     edx, dword_41159C
.text:0041157F                 call    j_@_RTC_CheckStackVars@8 ; _RTC_CheckStackVars(x,x)
.text:00411584                 pop     eax
.text:00411585                 pop     edx
.text:00411586                 pop     edi
.text:00411587                 pop     esi
.text:00411588                 pop     ebx
.text:00411589                 add     esp, 0E4h
.text:0041158F                 cmp     ebp, esp
.text:00411591                 call    j___RTC_CheckEsp
.text:00411596                 mov     esp, ebp
.text:00411598                 pop     ebp
.text:00411599                 retn
.text:00411599 _wmain          endp
.text:00411599
.text:00411599 ; ---------------------------------------------------------------------------

release

od

 

00401000  /$  51            push    ecx
00401001  |.  8B0D 40204000 mov     ecx, dword ptr [<&MSVCP90.std::c>;  MSVCP90.std::cin
00401007  |.  56            push    esi
00401008  |.  8D4424 04     lea     eax, dword ptr [esp+4]
0040100C  |.  50            push    eax
0040100D  |.  33F6          xor     esi, esi
0040100F  |.  FF15 5C204000 call    dword ptr [<&MSVCP90.std::basic_>;  MSVCP90.std::basic_istream<char,std::char_traits<char> >::operator>>
00401015  |.  8B08          mov     ecx, dword ptr [eax]
00401017  |.  8B49 04       mov     ecx, dword ptr [ecx+4]
0040101A  |.  8B5401 08     mov     edx, dword ptr [ecx+eax+8]
0040101E  |.  03C8          add     ecx, eax
00401020  |.  80E2 06       and     dl, 6
00401023  |.  0FBEC2        movsx   eax, dl
00401026  |.  F7D8          neg     eax
00401028  |.  1BC0          sbb     eax, eax
0040102A  |.  F7D0          not     eax
0040102C  |.  85C1          test    ecx, eax
0040102E  |.  74 2E         je      short 0040105E
00401030  |>  037424 04     /add     esi, dword ptr [esp+4]          ;  sum+=value
00401034  |.  8D4C24 04     |lea     ecx, dword ptr [esp+4]
00401038  |.  51            |push    ecx                             ;  value
00401039  |.  8B0D 40204000 |mov     ecx, dword ptr [<&MSVCP90.std::>;  MSVCP90.std::cin
0040103F  |.  FF15 5C204000 |call    dword ptr [<&MSVCP90.std::basic>;  MSVCP90.std::basic_istream<char,std::char_traits<char> >::operator>>
00401045  |.  8B10          |mov     edx, dword ptr [eax]
00401047  |.  8B4A 04       |mov     ecx, dword ptr [edx+4]
0040104A  |.  03C8          |add     ecx, eax
0040104C  |.  8B41 08       |mov     eax, dword ptr [ecx+8]
0040104F  |.  24 06         |and     al, 6
00401051  |.  0FBED0        |movsx   edx, al
00401054  |.  F7DA          |neg     edx
00401056  |.  1BD2          |sbb     edx, edx
00401058  |.  F7D2          |not     edx
0040105A  |.  85D1          |test    ecx, edx                        ;  是否是结束
0040105C  |.^ 75 D2         \jnz     short 00401030
0040105E  |>  A1 38204000   mov     eax, dword ptr [<&MSVCP90.std::e>
00401063  |.  8B0D 44204000 mov     ecx, dword ptr [<&MSVCP90.std::c>;  MSVCP90.std::cout
00401069  |.  50            push    eax
0040106A  |.  56            push    esi                              ;  sum
0040106B  |.  51            push    ecx
0040106C  |.  E8 4F010000   call    004011C0
00401071  |.  83C4 04       add     esp, 4
00401074  |.  8BC8          mov     ecx, eax
00401076  |.  FF15 64204000 call    dword ptr [<&MSVCP90.std::basic_>;  MSVCP90.std::basic_ostream<char,std::char_traits<char> >::operator<<
0040107C  |.  8BC8          mov     ecx, eax
0040107E  |.  FF15 68204000 call    dword ptr [<&MSVCP90.std::basic_>;  MSVCP90.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >::operator<<
00401084  |.  33C0          xor     eax, eax
00401086  |.  5E            pop     esi
00401087  |.  59            pop     ecx
00401088  \.  C3            retn

 

ida

.text:00401000
.text:00401000 ; =============== S U B R O U T I N E =======================================
.text:00401000
.text:00401000
.text:00401000 ; int __cdecl main(int temvalue, const char **argv, const char *envp)
.text:00401000 _main           proc near               ; CODE XREF: ___tmainCRTStartup+10Ap
.text:00401000
.text:00401000 value           = byte ptr -4
.text:00401000 temvalue        = dword ptr  4
.text:00401000 argv            = dword ptr  8
.text:00401000 envp            = dword ptr  0Ch
.text:00401000
.text:00401000                 push    ecx
.text:00401001                 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:00401007                 push    esi
.text:00401008                 lea     eax, [esp+8+value]
.text:0040100C                 push    eax
.text:0040100D                 xor     esi, esi
.text:0040100F                 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:00401015                 mov     ecx, [eax]
.text:00401017                 mov     ecx, [ecx+4]
.text:0040101A                 mov     edx, [ecx+eax+8]
.text:0040101E                 add     ecx, eax
.text:00401020                 and     dl, 6
.text:00401023                 movsx   eax, dl
.text:00401026                 neg     eax
.text:00401028                 sbb     eax, eax
.text:0040102A                 not     eax
.text:0040102C                 test    eax, ecx        ; 是否是结束
.text:0040102E                 jz      short printresult
.text:00401030
.text:00401030 whilecin:                               ; CODE XREF: _main+5Cj
.text:00401030                 add     esi, [esp+temvalue] ; esi为sum
.text:00401034                 lea     ecx, [esp+temvalue] ; temvalue
.text:00401038                 push    ecx
.text:00401039                 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:0040103F                 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:00401045                 mov     edx, [eax]
.text:00401047                 mov     ecx, [edx+4]
.text:0040104A                 add     ecx, eax
.text:0040104C                 mov     eax, [ecx+8]
.text:0040104F                 and     al, 6
.text:00401051                 movsx   edx, al
.text:00401054                 neg     edx
.text:00401056                 sbb     edx, edx
.text:00401058                 not     edx
.text:0040105A                 test    edx, ecx        ; 是否结束
.text:0040105C                 jnz     short whilecin  ; esi为sum
.text:0040105E
.text:0040105E printresult:                            ; CODE XREF: _main+2Ej
.text:0040105E                 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:00401063                 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:00401069                 push    eax
.text:0040106A                 push    esi             ; sum
.text:0040106B                 push    ecx
.text:0040106C                 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:00401071                 add     esp, 4
.text:00401074                 mov     ecx, eax
.text:00401076                 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:0040107C                 mov     ecx, eax
.text:0040107E                 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:00401084                 xor     eax, eax
.text:00401086                 pop     esi
.text:00401087                 pop     ecx
.text:00401088                 retn
.text:00401088 _main           endp
.text:00401088
.text:00401088 ; ---------------------------------------------------------------------------

 

posted @ 2010-06-20 16:18  南守拥  阅读(313)  评论(0编辑  收藏  举报