Clobbered registers

Andrew Haley aph@redhat.com
Mon Mar 12 04:28:00 GMT 2007


Facundo Ciccioli writes:
 > I wrote a function which modifies esp register through some asm
 > instructions (it pushes things to the stack). Everything works perfect
 > for now because the function takes care of restauring the content of
 > esp issuing an add instruction too so that it can return allright.

Right.  Good.  asms shouldn't clobber SP.  SP is controlled by the
compiler.

 > But reading GCC docs I found this:
 > 
 > "If you refer to a particular hardware register from the assembler
 > code, you will probably have to list the register after the third
 > colon to tell the compiler the register's value is modified."
 > 
 > Ok, so I do that. But looking at the assembler code generated by the
 > compiler I notice that it is exactly the same than before I did what
 > the docs say. So I wonder, why does the compiler needs to know if I
 > execute an instruction that modifies some register? And also (maybe
 > the answer to the former would respond this) why does the code doesn't
 > change?

If you use a specific hardware register, say R7, then you need to tell
the compiler you have done so, so that the compiler doesn't use that
register to store a temporary.

Andrew.



More information about the Gcc-help mailing list