This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: My inline assembly has the cooties.
- From: David Daney <ddaney at avtrex dot com>
- To: Marco Manfredini <mldb at gmx dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 15 Nov 2007 10:33:53 -0800
- Subject: Re: My inline assembly has the cooties.
- References: <200711151936.23916.mldb@gmx.net>
Marco Manfredini wrote:
Hi,
The first thing I always realize when I return to code with inline assembly
is, that I forgot the dodgy intricacies again. Today I seem to suffer from
paralytic blindness. Could someone please enlighten me, why this program
prints 20 with gcc 4.2.2 and 1010 with gcc-3.4.4?
I give up. Is it because you didn't declare %0 as an early clobber?
Perhaps it should be: ...."=&r"(r)...
David Daney
#if 0
gcc $0 -o ${0%.*}
exit 0
#endif
#include <stdio.h>
struct S
{
int v;
};
int main()
{
struct S a={10};
struct S b={1000};
int r=0;
__asm__ volatile(
"/*XXXXXXXXXXXXX [%0]=[%1]+[%2] XX */\n "
"\t movl %1,%0 \n"
"\t addl %2,%0 \n"
:"=r"(r)
:"g"(a.v),"g"(b.v));
printf("%d\n",r);
}
Cheers
Marco