The constructor of CPP disassembly analysis

Source: Internet
Author: User

The subclass constructor calls the parent class first. The subclass retains a piece of space for the parent class.

An example is given to analyze:

Class A  {public  :      A ()  {     }      ~a () {    cout<< "~a" <<endl;   }  };     Class B:public A  {public      :          B (a &a): _a (a)          {                       }          ~b ()          {              cout<< "~b" <<endl;          }      Private:          A _a;      };         int main (void)   {          a A;       It is simple to define a when a constructor          b b (a) is called;

Here's the disassembly code.

1: #include <iostream>2:using namespace Std;3:class A4: {5:public:6: A () 00401240 push EBP00401241 mov ebp,esp00401243 Sub esp,44h00401246 push ebx00401247 push esi004 01248 push edi00401249 push ecx0040124a Lea EDI,[EBP-44H]0040124D mov ecx,11h0040125  2 mov eax,0cccccccch00401257 rep stos dword ptr [edi]00401259 pop ecx0040125a mov DWORD PTR [ebp-4],ecx7: {8:cout << ' A construct ' << endl;0040125d push offset @ILT +35 (s Td::endl) (00401028) 00401262 push offset string "A construct" (0043201c) 00401267 push offset std::cout (         00439528) 0040126C call @ILT +180 (std::operator<<) (004010b9) 00401271 add esp,800401274 mov ecx,eax00401276 call @ILT +120 (std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040107d) 9:}0040127B mov eax,dword ptr [ebp-4]0040127e pop edi0040127f pop esi00401280 pop ebx004         01281 Add esp,44h00401284 cmp ebp,esp00401286 call __CHKESP (004096E0) 0040128B mov  esp,ebp0040128d pop ebp0040128e ret10:a operator= (const A &a) One by one: {12:cout << "operator =" << Endl;13:return a;14:}15:a (const a& a) copy constructor 004013b0 push EBP   004013B1 mov ebp,esp004013b3 Sub esp,44h004013b6 push ebx004013b7 push ESI004013B8          Push EDI004013B9 push ecx004013ba Lea EDI,[EBP-44H]004013BD mov ecx,11h004013c2 mov Eax,0cccccccch004013c7 Rep stos dword ptr [edi]004013c9 pop ECX004013CA mov dword ptr [E bp-4],ecx16: {17:cout << "const a&" << ENDL;004013CD push offset @ILT +35 (std::en  DL) (00401028) 004013d2 Push offset string "Const a&" (00432030) 004013d7 push offset std::cout (00439528) 004013DC call        @ILT +180 (std::operator<<) (004010b9) 004013E1 add ESP,8004013E4 mov ecx,eax004013e6 call    @ILT +120 (std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040107d):}004013eb    mov Eax,dword ptr [ebp-4]004013ee pop edi004013ef pop esi004013f0 pop ebx004013f1 Add ESP,44H004013F4 cmp Ebp,esp004013f6 call __CHKESP (004096e0) 004013FB mov esp,e         BP004013FD Pop ebp004013fe ret 419: ~a (): {004012b0 push EBP004012B1 mov Ebp,esp004012b3 Sub Esp,44h004012b6 push ebx004012b7 push esi004012b8 push edi004 012B9 push ecx004012ba Lea EDI,[EBP-44H]004012BD mov ECX,11H004012C2 mov eax,0ccccc Ccch004012c7 Rep STOs   DWORD ptr [EDI]004012C9 pop ECX004012CA mov dword ptr [ebp-4],ecx21:cout<< "~a" < &LT;ENDL;004012CD Push offset @ILT +35 (Std::endl) (00401028) 004012D2 push offset string "~a" (0043202c) 00   4012d7 Push offset std::cout (00439528) 004012DC call @ILT +180 (std::operator<<) (004010B9) 004012E1 Add ESP,8004012E4 mov ecx,eax004012e6 call @ILT +120 (Std::basic_ostream<char,std::char_trai   Ts<char> >::operator<<) (0040107d):}004012eb pop edi004012ec pop esi004012ed Pop ebx004012ee Add esp,44h004012f1 cmp ebp,esp004012f3 call __CHKESP (004096E0) 0040 12F8 mov esp,ebp004012fa pop ebp004012fb ret23:};24:25:class b:public A26: {27:public        : 28:b (a &a): _a (a): {00401310 push ebp00401311 mov ebp,esp00401313 push 0ffh00401315 push       Offset [Email protected]@[email protected]@@@z (0041fd79) 0040131A mov eax,fs:[00000000]00401320 Push eax00401321 mov dword ptr fs:[0],esp00401328 Sub esp,44h0040132b push ebx00401 32C push esi0040132d push edi0040132e push ecx0040132f Lea edi,[ebp-50h]00401332 mo V ecx,11h00401337 mov eax,0cccccccch0040133c rep stos dword ptr [edi]0040133e pop ecx0040 133F mov dword ptr [ebp-10h],ecx00401342 mov ecx,dword ptr [ebp-10h]00401345 call @ILT +80 (A:: A) (00401055) General Constructor Class B has a Class A object.   0040134A mov dword ptr [ebp-4],000401351 mov eax,dword ptr [ebp+8]00401354 push eax00401355           mov Ecx,dword ptr [ebp-10h]00401358 call @ILT +165 (a::a) (004010AA) copy constructor://_a = a;31:   }0040135D mov dword ptr [ebp-4],0ffffffffh00401364 mov eax,dword ptr [ebp-10h]00401367mov ecx,dword ptr [ebp-0ch]0040136a mov dword ptr fs:[0],ecx00401371 pop edi00401372 pop esi00401373 pop ebx00401374 Add esp,50h00401377 cmp ebp,esp00401379 call __chk           ESP (004096E0) 0040137E mov esp,ebp00401380 pop ebp00401381 ret 432: ~b () 33: {00401420 push ebp00401421 mov ebp,esp00401423 push 0ffh00401425 push offset [EMA Il protected]@[email protected] (0041fda2) 0040142A mov eax,fs:[00000000]00401430 push eax0040 1431 mov DWORD ptr fs:[0],esp00401438 Sub esp,44h0040143b push ebx0040143c push Esi0 040143D push edi0040143e push ecx0040143f Lea edi,[ebp-50h]00401442 mov ecx,11h00401 447 mov eax,0cccccccch0040144c rep stos dword ptr [edi]0040144e pop ecx0040144f mov dwo Rd PTR [ebp-10h],ecx00401452 mov dword ptr [ebp-4],134:cout<< "~b" <<endl;00401459 push offset @ILT +35 (Std::endl)   (00401028) 0040145E push offset string "~b" (0043203c) 00401463 push offset std::cout (00439528) 00401468   Call @ILT +180 (std::operator<<) (004010b9) 0040146D add esp,800401470 mov ecx,eax00401472           Call @ILT +120 (std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040107d) 35: }00401477 mov byte ptr [ebp-4],00040147b mov ecx,dword ptr [ebp-10h]0040147e call @ILT +1 Ten (A::~a) (00401073) 00401483 mov dword ptr [ebp-4],0ffffffffh0040148a mov ecx,dword ptr [ebp-10h]00401  48D call @ILT +110 (a::~a) (00401073) 00401492 mov ecx,dword ptr [ebp-0ch]00401495 mov dword ptr fs:[0],ecx0040149c pop edi0040149d pop esi0040149e pop ebx0040149f add esp,50h004 014A2 CMP        EBP,ESP004014A4 call __chkesp (004096e0) 004014a9 mov esp,ebp004014ab pop ebp004014ac   RET36:PRIVATE:37:A _a;38:};39:40:int main (void): {00401190 push ebp00401191         MOV ebp,esp00401193 push 0ffh00401195 push offset __ehhandler$_main (0041fd59) 0040119A mov EAX,FS:[00000000]004011A0 push EAX004011A1 mov dword ptr fs:[0],esp004011a8 Sub Esp,4ch0   04011AB push ebx004011ac push esi004011ad push edi004011ae Lea EDI,[EBP-58H]004011B1       MOV ECX,13H004011B6 mov EAX,0CCCCCCCCH004011BB rep stos dword ptr [Edi]42:a A;         It is simple to define a when a constructor is called 004011BD Lea ecx,[ebp-10h]004011c0 call @ILT +80 (a::a) (00401055) 004011C5 mov         DWORD ptr [Ebp-4],043:b B (a); 004011CC Lea EAX,[EBP-10H]004011CF push eax004011d0 Lea ecx,[ebp-14h]004011d3 call @ILT +155 (b::b) (004010a0) 44:return 0;004011d8 mov dword ptr [EBP-18H],0004011DF Lea Ecx,[ebp-14h]004011e2 call @ILT +130 (b::~b) (00401087) 004011E7 mov dword ptr [EBP-4],0FFFFFF Ffh004011ee Lea ECX,[EBP-10H]004011F1 call @ILT +110 (a::~a) (00401073) 004011F6 mov eax,dword p          TR [ebp-18h]45:}004011F9 mov ecx,dword ptr [EBP-0CH]004011FC mov dword ptr fs:[0],ecx00401203 pop edi00401204 pop esi00401205 pop ebx00401206 add esp,58h00401209 cmp ebp,e sp0040120b call __chkesp (004096e0) 00401210 mov esp,ebp00401212 pop ebp00401213 ret@ilt+145         (_main): 00401096 jmp Main (00401190) @ILT +155 ([email protected]@[email protected]@@@z): 004010a0 jmp B::b (00401310) @ILT +165 ([email protected]@[email protected]@@z): 004010AA jmp a::a (004013b0) replication function @ilt+110 ([email Protected]@[email protected]): 00401073 jmp a::~a (004012b0) @ILT +130 ([Email protected]@[email prot         Ected]: 00401087 jmp b::~b (00401420) @ILT +80 ([email protected]@[email protected]): 00401055 jmp A::a (00401240) General constructors


The constructor of CPP disassembly analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.