I need to call a function pointer using gcc that i can´t typedef in c++. I´m not good at asm so i would appreciate your help.
The function passes arg1 in eax and arg2 in esi. args are pushed right to left and the caller cleans the stack
signed int __usercall o_Fkt<eax>(int a1<eax>, int a2<esi>, int a3, int a4, int a5)
edit: Thanks Willem. I had success calling it this way:
int callfn(void* a1, void* a2, int a3, int a4, void* a5 )
{
int result;
unsigned long fktAddr = 0x0092FE40;
__asm volatile(
"push %[a5]\n\t"
"push %[a4]\n\t"
"push %[a3]\n\t"
"call edx\n\t"
"add esp, 12"
: "=a" (result)
: "d" (fktAddr), "a" (a1), "S" (a2) , [a5] "r" (a5), [a4] "r" (a4), [a3] "r" (a3)
: "memory"
);
return result;
}
edit2: added "memory" to clobber list
something like this - i did not test it, but the compiler output looks ok i think.
The
=a
output constraint causes the return value to be copied intoresult
, thea
input constraint loadsa1
ineax
, andS
loadsa2
intoesi
the rest is just pushing the other arguments.