Help! Program crashed when call the inline assembly function continuously

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

 



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.


[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