From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12943 invoked by alias); 6 Jul 2009 15:07:55 -0000 Received: (qmail 12930 invoked by uid 22791); 6 Jul 2009 15:07:54 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Jul 2009 15:07:47 +0000 Received: from zps37.corp.google.com (zps37.corp.google.com [172.25.146.37]) by smtp-out.google.com with ESMTP id n66F7jsS002774 for ; Mon, 6 Jul 2009 08:07:45 -0700 Received: from pzk14 (pzk14.prod.google.com [10.243.19.142]) by zps37.corp.google.com with ESMTP id n66F7gEh021274 for ; Mon, 6 Jul 2009 08:07:43 -0700 Received: by pzk14 with SMTP id 14so4232183pzk.32 for ; Mon, 06 Jul 2009 08:07:42 -0700 (PDT) Received: by 10.115.110.6 with SMTP id n6mr7669882wam.58.1246892862727; Mon, 06 Jul 2009 08:07:42 -0700 (PDT) Received: from localhost.localdomain.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id j31sm11285380waf.33.2009.07.06.08.07.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 06 Jul 2009 08:07:42 -0700 (PDT) To: Lennyk 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> From: Ian Lance Taylor Date: Mon, 06 Jul 2009 15:07:00 -0000 In-Reply-To: <4A51AA7D.4060809@gmail.com> (Lennyk's message of "Mon\, 06 Jul 2009 10\:40\:45 +0300") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-System-Of-Record: true 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/msg00086.txt.bz2 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