This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: undefined reference to... when using intel inline asm


Lennyk <lennyk430@gmail.com> writes:

> According to the guide - the corresponding GCC translation - should
> look like this:
>
> void bswap(int* n)
> {
>    asm("movl       %0, %%eax" : : "g" (*n));
>    asm("bswap    %eax");
>    asm("movl      %%eax, %0" : "=g" (*n));
> }
>
> But, for some reason, the result is not a "bswapped" n.
> Why?

* What does the generated code look like?
* You shouldn't break up the asm statements like that--write one asm
  with three assembler statements.
* Let the compiler do the data movement for you; it's good at it.
* If you're going to clobber %eax in an asm, you need to say so
  explicitly; that's probably why this code sequence is breaking.
  asm("bswap %%eax" : : : "eax");

Anyhow, I would write it like this:

void bswap(int* n)
{
  asm("bswap %0" : "=r" (*n) : "0" (*n));
}

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]