[求助]关于thiscall调用的this指针由ecx传递问题
;请教this指针是如何传给ECX的?怎么看出this指针是对象的地址呢?谢谢!
//源代码如下:
/*******************************************************
* this指针 *
* (c) 看雪软件安全网站 www.pediy.com 2000-2008 *
********************************************************/
#include <stdio.h>
class CSum
{
public:
int Add(int a, int b) //实际Add原型具有如下形式:Add(this,int a,int b)
{
return (a + b);
}
};
void main()
{
CSum sum;
sum.Add(1, 2);
}
;部分反汇编代码如下:
; sum.Add(1,2)
00401000 /$ 55 push ebp
00401001 |. 8BEC mov ebp, esp
00401003 |. 51 push ecx
00401004 |. 6A 02 push 2
00401006 |. 6A 01 push 1
00401008 |. 8D4D FC lea ecx, dword ptr [ebp-4]
0040100B |. E8 10000000 call 00401020
00401010 |. 8BE5 mov esp, ebp
00401012 |. 5D pop ebp
00401013 \. C3 retn
; int Add(int a, int b){}
00401020 /$ 55 push ebp
00401021 |. 8BEC mov ebp, esp
00401023 |. 51 push ecx
00401024 |. 894D FC mov dword ptr [ebp-4], ecx
00401027 |. 8B45 08 mov eax, dword ptr [ebp+8]
0040102A |. 0345 0C add eax, dword ptr [ebp+C]
0040102D |. 8BE5 mov esp, ebp
0040102F |. 5D pop ebp
00401030 \. C2 0800 retn 8