Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C++ source:
void call_by_reference(int& x)
{
x = 20;
}
void call_by_pointer(int* x)
{
*x = 20;
}
void call_by_value(int x)
{
x = 20;
}
int _tmain(int argc, _TCHAR* argv[])
{
int y = 0;
call_by_reference(y);
call_by_pointer(&y);
call_by_value(y);
return 0;
}
Disassembly:
The most important lines are 50-51 (by-reference) and 55-56 (by-pointer)
as we see, the same - load effective address and push to stack
int _tmain(int argc, _TCHAR* argv[])
{
00F81480 push ebp
00F81481 mov ebp,esp
00F81483 sub esp,0CCh
00F81489 push ebx
00F8148A push esi
00F8148B push edi
00F8148C lea edi,[ebp-0CCh]
00F81492 mov ecx,33h
00F81497 mov eax,0CCCCCCCCh
00F8149C rep stos dword ptr es:[edi]
int y = 0;
00F8149E mov dword ptr [y],0
call_by_reference(y);
00F814A5 lea eax,[y]
00F814A8 push eax
00F814A9 call call_by_reference (0F81005h)
00F814AE add esp,4
call_by_pointer(&y);
00F814B1 lea eax,[y]
00F814B4 push eax
00F814B5 call call_by_pointer (0F8100Fh)
00F814BA add esp,4
call_by_value(y);
00F814BD mov eax,dword ptr [y]
00F814C0 push eax
00F814C1 call by_value (0F8100Ah)
00F814C6 add esp,4
return 0;
00F814C9 xor eax,eax
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment