GCC calling convention
GCC calling convention
I want to call a C-Function from within an asm-function, and pass parameters to it, but I don't know the calling convention.
Re: GCC calling convention
You have to pass parameters right-to-left. That is, if you have a function:
int x(x1, x2, x3)
you have to do this:
push x3
push x2
push x1
call x
add $0x0C, %esp
In case you use NASM or TASM replace the last line with:
add esp,0Ch
Also, the GCC calling conventions assume (AFAIK) that ebx, esi, edi and ebp are preserved during the call (and the segment registers, of course, as well).
So.. it's rather easy.. you just have to push the arguments in reverse order and clean up the stack afterwards..
int x(x1, x2, x3)
you have to do this:
push x3
push x2
push x1
call x
add $0x0C, %esp
In case you use NASM or TASM replace the last line with:
add esp,0Ch
Also, the GCC calling conventions assume (AFAIK) that ebx, esi, edi and ebp are preserved during the call (and the segment registers, of course, as well).
So.. it's rather easy.. you just have to push the arguments in reverse order and clean up the stack afterwards..