Help! Program crashed when call the inline assembly function continuously
spark.z
spark.yj.zhao@gmail.com
Wed Mar 31 14:18:00 GMT 2010
Eclipse + gcc-4.4.1, compiled the program with optimization flag -O2
I wrote a inline function with inlined assembly
void pincrement(int* target)
{
__asm__ __volatile__ ("pushl %eax");
__asm__ __volatile__ ("lock ; incl (%%eax)" ::"a"(target));
__asm__ __volatile__ ("popl %eax");
}
and call it in the main function like:
int main()
{
static int my_an = 0;
pincrement(&my_an);
pincrement(&my_an);
pincrement(&my_an);
printf("my_an is %d\n",my_an);
}
It crashed when run the app. So I check the assembly code of the app. The
complier translate the three pincrement call become:
push eax
mov eax, offset dword_474048
lock inc dword ptr [eax]
pop eax
push eax
lock inc dword ptr [eax]
pop eax
push eax
lock inc dword ptr [eax]
pop eax
It only has one "mov eax, offset dword_474048" sentence in it.
How can I tell the gcc complier to inline the whole assembly function three
times completely?
:working:
--
View this message in context: http://old.nabble.com/Help%21-Program-crashed-when-call-the-inline-assembly-function-continuously-tp28094526p28094526.html
Sent from the gcc - Help mailing list archive at Nabble.com.
More information about the Gcc-help
mailing list