Inline assembly questions

Zack Weinberg zack@codesourcery.com
Mon Apr 7 12:04:00 GMT 2003


Stephen Biggs <xyzzy@hotpop.com> writes:

> When executing in a different code section, why do I have to do:
>
>   asm ( " lea	%%cs:SomeFunction,%%eax" : : : "%eax" );
>   asm ( " call	*%%eax" : : : "%eax");
>
> ... when what I want to do is this (which goes off into never-never
> land):
>   asm ( " call	*%%cs:SomeFunction" : : : "%eax" );

Because there is no absolute-jump-to-immediate instruction on the x86.
The hardware instruction that "call *%cs:addr" maps to is PC-relative.
You have no choice but to use a scratch register.

Also, the above constitutes lying to the compiler about control flow;
the correct thing to do is

{
  void (*ptr)(void);
  asm ("lea %%cs:SomeFunction, %0" : "=r" (ptr))
  ptr();
}

> Also, how do I make a function in a GCC C file that is strictly
> inline assembly be completely bare with no prologue/epilogue (stack
> frame) or optimizations?

You write an .s file and feed it directly to the assembler.

zw



More information about the Gcc mailing list