From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25203 invoked by alias); 7 Jul 2009 10:51:42 -0000 Received: (qmail 25192 invoked by uid 22791); 7 Jul 2009 10:51:41 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-ew0-f225.google.com (HELO mail-ew0-f225.google.com) (209.85.219.225) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Jul 2009 10:51:33 +0000 Received: by ewy25 with SMTP id 25so5815710ewy.8 for ; Tue, 07 Jul 2009 03:51:30 -0700 (PDT) Received: by 10.210.112.1 with SMTP id k1mr5861159ebc.11.1246963890818; Tue, 07 Jul 2009 03:51:30 -0700 (PDT) Received: from ?192.168.43.19? ([212.143.139.215]) by mx.google.com with ESMTPS id 7sm240623eyg.57.2009.07.07.03.51.29 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 07 Jul 2009 03:51:29 -0700 (PDT) Message-ID: <4A5328AD.10006@gmail.com> Date: Tue, 07 Jul 2009 10:51:00 -0000 From: Lennyk User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Ian Lance Taylor CC: gcc-help@gcc.gnu.org Subject: Re: undefined reference to... when using intel inline asm References: <4A4C69F0.7040201@gmail.com> <4A51AA7D.4060809@gmail.com> In-Reply-To: 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: 2009-07/txt/msg00102.txt.bz2 Ian Lance Taylor wrote: > Lennyk 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 > > Thanks Ian! After going over the GCC-Inline Assembly guides - I think I'm starting to get the hang of it. Thanks for your assistance!