当参数为对象及返回值为对象时的情景分析
void SetClass(People obj){
;
}
People thePe1(10,20,"Hello,MyName!");
SetClass(thePe1);
21: People thePe1(10,20,"Hello,MyName!");
004010FD push offset string "Hello,MyName!" (0042801c)
00401102 push 14h
00401104 push 0Ah
00401106 lea ecx, // 我们自己创建的对象的空间
00401109 call @ILT+45(People::People) (00401032)
0040110E mov dword ptr ,0// EAX 返回this指针 对象的首地址
22: SetClass(thePe1);
00401115 sub esp,10h// 申请对象的空间
00401118 mov ecx,esp// 新对象的this指针
0040111A mov dword ptr ,esp // 临时空间 存放this指针
0040111D lea eax,// 这里其实不用复制this指针也可
00401120 push eax // EAX 为构造函数的参数
00401121 call @ILT+50(People::People) (00401037)
00401126 mov dword ptr ,eax//将生成的临时对象的this指针赋值给
00401129 call @ILT+20(SetClass) (00401019) // 此事 临时对象 已经全部压入堆栈了
0040112E add esp,10h
从构造临时对象到函数的调用 这里的临时对象的压栈太NX了
进入call SetClass 之后
004010A8|.8D4D 08 LEA ECX,DWORD PTR SS:
004010AB|.E8 6EFFFFFF CALL ClassPar.0040101E// 这里就是临时对象的地址
一切均为对象!
People RetClass(){
static People thePe;
return thePe;
}
People thePe1(10,20,"Hello,MyName!");
RetClass();
32: RetClass();
00401205 lea eax,
00401208 push eax // 太NB了
00401209 call @ILT+30(RetClass) (00401023)
0040120E add esp,4
00401211 lea ecx,
00401214 call @ILT+25(People::~People) (0040101e)
12: People RetClass()
13: {
004010E0 push ebp
004010E1 mov ebp,esp
004010E3 sub esp,44h
004010E6 push ebx
004010E7 push esi
004010E8 push edi
004010E9 lea edi,
004010EC mov ecx,11h
004010F1 mov eax,0CCCCCCCCh
004010F6 rep stos dword ptr
004010F8 mov dword ptr ,0
14: static People thePe;
004010FF xor eax,eax
00401101 mov al,[`RetClass'::`2'::$S1 (0042e058)]
00401106 and eax,1
00401109 test eax,eax
0040110B jne RetClass+53h (00401133)
0040110D mov cl,byte ptr [`RetClass'::`2'::$S1 (0042e058)]
00401113 or cl,1
00401116 mov byte ptr [`RetClass'::`2'::$S1 (0042e058)],cl
0040111C mov ecx,offset type_info `RTTI Type Descriptor'+970h (0042e048)
00401121 call @ILT+65(People::People) (00401046)
00401126 push offset $E2 (00401180)
0040112B call atexit (004017a0)
00401130 add esp,4
15: return thePe;
00401133 push offset type_info `RTTI Type Descriptor'+970h (0042e048)
00401138 mov ecx,dword ptr
0040113B call @ILT+55(People::People) (0040103c)
00401140 mov edx,dword ptr
00401143 or edx,1
00401146 mov dword ptr ,edx
00401149 mov eax,dword ptr
16: }
0040114C pop edi
0040114D pop esi
0040114E pop ebx
0040114F add esp,44h
00401152 cmp ebp,esp
00401154 call __chkesp (004016b0)
00401159 mov esp,ebp
0040115B pop ebp
0040115C ret
页:
[1]