Mail Archives: djgpp/1998/12/07/14:29:02
SynthHack wrote:
>
> HI,
>
> How can I pass arguments (or variables) from DJGPP to a function I made in
> NASM? (And created a coff file with it)...
The best way is probably to make your NASM function conform to GCC's
calling conventions. This means:
* Stack layout is as follows:
Last argument
...
Second argument [esp+8]
First argument [esp+4]
Return address [esp]
This assumes all arguments are `int', pointers, or `float'. A `double'
will occupy two such slots (`double's are not by default aligned on the
stack). You should avoid passing structs on the stack; it gets very
complicated.
* The return value, if an integer or pointer, should be placed in eax.
If a floating point value, leave it in the FPU top-of-stack register.
Don't try to return structures, it too is complicated.
* You may modify registers eax, ecx, edx and the FPU registers. Others
should be saved and restored.
Then declare the function appropriately in your C header. (If using
C++, use `extern "C"'.)
If you want to use your own calling conventions, you'll have to use
inline asm from GCC to call the function. So, if an asm function `frob'
is passed a value in ebx and modifies it in place, clobbering ecx:
int n;
...
asm("call frob" : "=b" (n) : "0" (n) : "ecx");
This is probably not the best solution. The first way is better, IMHO,
unless there are special considerations.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -