From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20016 invoked by alias); 16 Feb 2011 10:32:11 -0000 Received: (qmail 20006 invoked by uid 22791); 16 Feb 2011 10:32:10 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Feb 2011 10:32:04 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1GAW2OI000473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Feb 2011 05:32:02 -0500 Received: from zebedee.pink (ovpn-113-145.phx2.redhat.com [10.3.113.145]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1GAW1DA015934; Wed, 16 Feb 2011 05:32:02 -0500 Message-ID: <4D5BA7A1.7030800@redhat.com> Date: Wed, 16 Feb 2011 10:33:00 -0000 From: Andrew Haley User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Re: need volatile for asm? References: <4D5B1310.5070406@andihellmund.com> In-Reply-To: <4D5B1310.5070406@andihellmund.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00229.txt.bz2 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 >> >> 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 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.