Mail Archives: djgpp/1998/03/25/04:13:00
At 05:38 3/24/1998 +0100, John Kismul wrote:
>Can anyone here tell me how I call a function from inside a asm
>statement.
>
>Like:
>
>__asm__("
>
>
>call hello1(34) I know this won't work
>call hello2 but this will.
>"
>);
>
>So how do I call a function and pass any parameters to it?
Push the parameters on the stack, right to left, then call the function. Its
return value will be left in %eax, assuming it's an int or pointer. You can
be lazy and just use its name preceded by an underscore, or do it right with
the GCC asm features (see its docs). Here's an example. This code:
void foo(int x, int y);
f() {
foo(1, 2);
}
is equivalent to this:
void foo(int x, int y);
g() {
asm("pushl $2 ;"
"pushl $1 ;"
"call %0 ;"
: /* No outputs */
: "i" (foo)); /* Insert `foo's address in place of %0 */
}
Nate Eldredge
eldredge AT ap DOT net
- Raw text -