www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/25/04:13:00

Date: Tue, 24 Mar 1998 21:54:18 -0800 (PST)
Message-Id: <199803250554.VAA20199@adit.ap.net>
Mime-Version: 1.0
To: john DOT kismul AT bergen DOT mail DOT telia DOT com, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Calling functions from within an '__asm__(" ")' statement

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019