//compiler: visual c++
//system: win7
#define pureasmcall(retval)\
__declspec(naked) retval _stdcall
// desc: directly return n
pureasmcall(int) getparam(int)
{
__asm{
push ebp
mov ebp,esp
add ebp,8
mov eax,[ebp]
pop ebp
ret 4
}
}
// desc: return a+b
pureasmcall(int) add(int a, int b)
{
__asm{
push ebp
mov ebp,esp
add ebp,8
mov eax,[ebp]
add eax,[ebp+4]
pop ebp
ret 8
}
}
// desc: directly return the pointer
pureasmcall(char*) getpointer(char * p)
{
__asm{
push ebp
mov ebp,esp
add ebp,8
mov eax,[ebp]
pop ebp
ret 4
}
}
class CC
{
public:
CC():a(11),b(22){}
int a;
int b;
};
pureasmcall(int) getclassvar(const CC *)
{
__asm{
push ebp
mov ebp,esp
add ebp,8
// get the class object address
mov esi,[ebp] //error: mov esi,p
mov eax,[esi]
pop ebp
ret 4
}
}
int main(int argc, char * argv[])
{
printf("value: %d\n", getparam(5));
printf("addr: %d\n", add(4,5));
char * p = "abc";
printf("address:%x %x\n", getpointer(p), p);
CC cc;
printf("class var:%d\n", getclassvar(&cc));
return 1;
}