public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Lennyk <lennyk430@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: undefined reference to... when using intel inline asm
Date: Mon, 06 Jul 2009 15:07:00 -0000	[thread overview]
Message-ID: <m3hbxpn937.fsf@google.com> (raw)
In-Reply-To: <4A51AA7D.4060809@gmail.com> (Lennyk's message of "Mon\, 06 Jul 2009 10\:40\:45 +0300")

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

  reply	other threads:[~2009-07-06 15:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-02  8:04 Lennyk
2009-07-02 19:52 ` Ian Lance Taylor
2009-07-06  7:40   ` Lennyk
2009-07-06 15:07     ` Ian Lance Taylor [this message]
2009-07-07 10:51       ` Lennyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3hbxpn937.fsf@google.com \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=lennyk430@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).