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]

Help! Program crashed when call the inline assembly function continuously


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]