Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Inline assembly and gcc

Author: Dieter Buerssner

Date: 10:44:45 05/21/04

Go up one level in this thread


On May 21, 2004 at 13:08:43, Christophe Drieu wrote:

>It's ok now, Thank you bob.
>
>	a=4;b=0;
>
>	__asm__ (
>		"movl %0, %%eax"			"\n\t"
>		"incl %%eax"				"\n\t"
>		"movl %%eax, %1"			"\n\t"
>		"movl %%eax, %2"			"\n\t"
>	:"=g"(a)
>	:"g"(b),"g"(a)
>	:"ax","memory"
>	);
>
>	printf("a=%d b=%d\n", a, b); // a=5 b=5

I think, this is still not correct. You did not tell the compiler, that you
changed b. In you example, b is output, but you told the compiler, it is input.

>PS: Is there any way to let the compiler choose the register to use ?

Untested:

int tmp;
	__asm__ (
		"movl %0, %2"			"\n\t" // tmp = a;
		"incl %2"			"\n\t" // tmp++;
		"movl %2, %1"			"\n\t" // b=tmp;
		"movl %2, %0"			"\n\t" // a=tmp;
	: "=g"(a), "=g" (b), "=r&" (tmp)
	: "0"(a));

To let the compiler chose a register, I introduced a temporary variable tmp "r&"
means, put it in any suitable register you like, it will be accessed before all
input is consumed (not sure, if the & is needed here, because actually it is
used at the same time, this could then yield in code like move eax, eax; which
probably would work). Note also the difference in the input to your example ("g"
(a) vs. "0" (a)). You don't need a clobber list in this case.

Regards,
Dieter



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.