From: Andrew Haley <aph@redhat.com>
To: gcc-help@gcc.gnu.org
Subject: Re: need volatile for asm?
Date: Wed, 16 Feb 2011 10:33:00 -0000 [thread overview]
Message-ID: <4D5BA7A1.7030800@redhat.com> (raw)
In-Reply-To: <4D5B1310.5070406@andihellmund.com>
On 02/15/2011 11:58 PM, Andi Hellmund wrote:
> On 02/16/2011 12:11 AM, kevin diggs wrote:
>> Hi,
>>
>> Does the asm in:
>>
>> #include<stdio.h>
>>
>> int main(int argc, char *argv[])
>> {
>> unsigned int pc;
>>
>> asm("\n\t"
>> "call 1f\n\t"
>> "1: pop %0\n"
>> :"=g"(pc)
>> );
>>
>> printf(__FILE__"`%s()-%d: %%pc is %p\n",__func__,__LINE__,pc);
>>
>> return 0;
>> }
>>
>> need volatile?
>
> no, you don't need the volatile keyword since the output operand
> (pc) is live after the asm statement which puts a side-effect on the
> asm statement.
I'm not sure about that. Because there is no input operand, gcc is
free to move the asm. Volatile will prevent that from happening.
I'd do this:
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned int pc;
pc = (unsigned int)&&label;
label:
printf(__FILE__"`%s()-%d: %%pc is %p\n",__func__,__LINE__,pc);
return 0;
}
Andrew.
next prev parent reply other threads:[~2011-02-16 10:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-15 23:58 kevin diggs
2011-02-16 5:25 ` Andi Hellmund
2011-02-16 10:33 ` Andrew Haley [this message]
2011-02-16 10:59 ` Drasko DRASKOVIC
2011-02-16 11:18 ` Andi Hellmund
2011-02-16 12:12 ` David Brown
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=4D5BA7A1.7030800@redhat.com \
--to=aph@redhat.com \
--cc=gcc-help@gcc.gnu.org \
/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).