Disassembly of a simple C + + program

Source: Internet
Author: User

  
 
  1. #include<iostream>
  2. using namespace std;
  3. class point3d;
  4. class point2d;
  5. class point3d
  6. {
  7. private:int x; int y; int z;
  8. public:
  9. Point3D(inta= 0, intb= 0, intC= 0) :x(a),y(b),Z(C) {}
  10. };
  11. class point2d
  12. {
  13. int a;
  14. int b;
  15. public:
  16. point2d(int x=0,int y=0):a(x),b(y){}
  17. operator point3d()
  18. {
  19. return{ a,b,0 };
  20. }
  21. };
  22. int main()
  23. {
  24. point2d z;
  25. point3d q = z;
  26. return 0;
  27. }
Post Disassembly point 2d Z: (Call constructor Push 0 (Press 2 arguments) push 0lea ecx,[z] (Save Z object's address to ECX) Call point2d::p oint2d (0c01348h)
mov dword ptr [THIS],ECXThe ECX (the address of the Z object). Save to this pointer
mov Eax,dword ptr [this]. Assigns the address of the Z object to the EAXmov Ecx,dword ptr [x]; Remove the value of the variable x to save to ECXmov dword ptr [EAX],ECX. Assigns ecx=0 to the lower 4 bits of the object Z (that is, a)mov Eax,dword ptr [this]. Assigns the address of the object to the EAXmov ecx,dword ptr [y] assigns the value of the variable y to ecxmov dword ptr [EAX+4],ECX assigns the value of Y to the address of a high 4-bit object (that is, b)mov Eax,dword ptr [this], the address of the object to EAX as the return value

Point3D Q =z;
  
 
  1. 008538B4 lea eax,[q] ;将q的地址赋给eax
  2. 008538B7 push eax ;压栈.作为参数
  3. 008538B8 lea ecx,[z] ;将z的地址赋给ecx
  4. 008538BB call point2d::operator point3d (085133Eh)
  
 
  1. 00853380 push ebp
  2. 00853381 mov ebp,esp
  3. 00853383 sub esp,0CCh
  4. 00853389 push ebx
  5. 0085338A push esi
  6. 0085338B push edi
  7. 0085338C push ecx
  8. 0085338D lea edi,[ebp-0CCh]
  9. 00853393 mov ecx,33h
  10. 00853398 mov eax,0CCCCCCCCh
  11. 0085339D rep stos dword ptr es:[edi]
  12. 0085339F pop ecx ;
  13. 008533A0 mov dword ptr [this],ecx ;将 point2d z的地址赋给了this指针
  14. return{ a,b,0 };
  15. 008533A3 push 0 ;0压栈
  16. 008533A5 mov eax,dword ptr [this]
  17. 008533A8 mov ecx,dword ptr [eax+4] ;将z的a变量的值赋给ecx
  18. 008533AB push ecx ;ecx压栈
  19. 008533AC mov edx,dword ptr [this]
  20. 008533AF mov eax,dword ptr [edx] ;将a的值赋给了eax中
  21. 008533B1 push eax ;eax压栈
  22. 008533B2 mov ecx,dword ptr [ebp+8] ;取出q的地址
  23. 008533B5 call point3d::point3d (0851357h) ;point3d(一个q的地址.参数.3个变量参数)
  24. 008533BA mov eax,dword ptr [ebp+8] ;将q的地址取出来.作为返回值
  25. }










From for notes (Wiz)

Disassembly of a simple C + + program

Related Article

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.