This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: need volatile for asm?


On 02/16/2011 12:11 AM, kevin diggs wrote:
Hi,

Does the asm in:

#include<stdio.h>

int main(int argc, char *argv[])
{
unsigned int pc;

	asm("\n\t"
		"call 1f\n\t"
		"1: pop %0\n"
		:"=g"(pc)
	);

printf(__FILE__"`%s()-%d: %%pc is %p\n",__func__,__LINE__,pc);

	return 0;
}

need volatile?

Thanks!

kevin


Hey Kevin


no, you don't need the volatile keyword since the output operand (pc) is live after the asm statement which puts a side-effect on the asm statement.

A possible way to verify the need of volatile would be to compile the code at a high optimization level, e.g. -O3 and check the assembly code (-S option) if the inline assembly was removed or NOT.

Best regards,
Andi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]