Talk:X86 Disassembly/Calling Convention Examples

gcc
If you have gcc 3.0 or higher, Linux uses the -mregparm=3 option to put 3 args in registers. For per-function control, it does this:


 * 1) define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
 * 2) define FASTCALL(x)    x __attribute__((regparm(3)))
 * 3) define fastcall       __attribute__((regparm(3)))

Usage in a header file:

extern void FASTCALL(__up_read(struct rw_semaphore *sem));

Usage in a C file:

void fastcall sched_exit(task_t * p) {

While gcc on Windows does support a few odd Microsoftisms, that's not really the way gcc is meant to be used.

Also, on x86-64, gcc puts up to 6 integer arguments in registers without being affected by floating-point usage. (8 args for double, and 8 args for float)

AlbertCahalan 06:29, 3 October 2005 (UTC)

errors
From here, http://en.wikibooks.org/wiki/Reverse_Engineering/Calling_Conventions

"STDCALL passes arguments right-to-left, and returns the value in eax. (The Microsoft documentation erroneously claims that arguments are passed left-to-right, but this is not the case: see the Calling Conventions Example page for details.)"

From here, http://en.wikibooks.org/wiki/Reverse_Engineering/Examples/Calling_Conventions

"Notice that y is a higher offset from ebp, which indicates that these arguments are passed on the stack from left-to-right, instead of right-to-left as the Microsoft documentation claims."

One must be wrong. It appears this page is in error. y is located at ebp+12 and x is located at ebp+8, so y is pushed first, or right-to-left.

Also, MASM 5.1 documentation defines STDCALL as selecting between CDECL and PASCAL for variable and fixed arguments, respectively. You've presented STDCALL as CDECL only in the MS and GNU C summary.

I modified the page to indicate that in this example the stdcall function takes arguments right-to-left. 63.241.31.130 (talk) 01:18, 6 June 2008 (UTC)