clobbering input args in inline asm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

As probably many of the new gcc users, I stumbled over
the fact that gcc allows an inline asm to modify the
input arguments, and there seem to be no other way
of preventing that, than to use the dummy output var.
And, just as all the others who stumbled over this, I
found that solution counter-intuitive. So I tried some
other things, and now I have a few questions.
Below is the program that prints the different results
when compiled with -O0 and -O2, and the fact that the
asm constraints are broken, is really counter-intuitive,
IMHO.

My questions are:
- I can't add the register both in the input list and the
clobber list, and that's perfectly documented. However, it
seems like I can add "0" in the clobber list, and gcc accepts
that. Though, it still doesn't give the right code. I wasn't
able to find in the gcc manual, nor in the google, what will
the "0" mean in the clobber list - so what is it?
- Another strange thing is that I can add "0" in the clobber
list if it refers to any of the register classes (on i386
target), but not to "a". I.e. if I have "b" in input and "0"
in clobber - gcc eats that. If I have "a" in input and "0"
in clobber - gcc complains. What is the reason?
- Why wouldn't gcc just allow the "&" modifier in the
input list? Just like in the output list it means early-clobber,
in the input list it could mean late-clobber, i.e. clobbered
after the value was taken.

Sorry for the novice questions. This is mainly just my curiosity
and the fact that I find an official solution very confusing and
counter-intuitive.

Thanks for any info.


The test-case:
---
#include <stdio.h>

volatile int a = 5;

int main()
{
 int b = a;
 asm volatile ("movl $0, %%ebx\n" :: "b"(b));
 printf("%i\n", b);
 return 0;
}
---
Prints 5 when compiled with -O0, and 0 when compiled with -O1.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux