I'm new to asm x86 and I've been looking for a while why, on x86 / visual C++ 2010 , a function call like this :
void test()
{
vector2f vec;
vec.x = 1.f;
vec.y = 1.f;
vec = something_on_vector2f(vec);
}
given :
struct vector2f
{
vector2f() {}
float x;
float y;
};
vector2f something_on_vector2f(vector2f vec)
{
return vec;
}
generates an assembly code with such a big stack allocation (224 bytes) and 3 'push' instead of the 2 expected (push 'x' + push 'y')
...
00FBB780 55 push ebp
00FBB781 8B EC mov ebp,esp
00FBB783 81 EC E0 00 00 00 sub esp,0E0h (???)
...
002DB7B0 8B 45 F8 mov eax,dword ptr [ebp-8] (push 'x')
002DB7B3 50 push eax
002DB7B4 8B 4D F4 mov ecx,dword ptr [vec] (push 'y')
002DB7B7 51 push ecx
002DB7B8 8D 95 24 FF FF FF lea edx,[ebp-0DCh] (push '???')
002DB7BE 52 push edx
002DB7BF E8 4B E7 FF FF call normalize_vector2f (2D9F0Fh)
...
What are the extra push and extra stack allocation for ?
I'm using libjit and only 2 push are generated => that creates a bug when calling the function from JIT code as the native code does not expect the arguments in the stack at the same EBP offset.