Mail Archives: djgpp/1996/05/30/22:32:43
Shawn Hargreaves <slh100 AT york DOT ac DOT uk> wrote:
>On Mon, 27 May 1996, Richard Philp wrote:
>Arguments from C to the assembler function are passed on the stack, the
>caller pushes them and then cleans up the stack after the asm function
>returns. The return value is normally in %eax, at least for integers. I
>would imagine pointers are the same, but floats and structures probably
>different.
The passing of 32-bit and less arguments is normally by %eax if
optimizing. There are some compiler switches that select whether to
pass floating point in registers or on the stack. There are also
switches that will cause small structures to be passed in registers as
well, so I would not count on these unless I found the switches and
explicity turned them off for all the compilation. Just look in the
gcc docs under invoking...
>The easiest way to figure this out is to write a simple C function that
>takes some parameters and returns something, and compile it with -S. Take
>a look at the resulting .s file, and you can see exactly where gcc put
>everything...
When compiling with optimisations it might come down to the whim of
the compiler what it chooses to do in some cases (esp with structures)
although I'm no expert here, so correct me if I'm wrong. Still
remember to compile the function with exactly the same switches as you
would the rest of your program, and with the same function prototype
as the assembly function you want to write. This way you can be most
sure that the assembler output will be consistent.
Malcolm
- Raw text -