public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help! Program crashed when call the inline assembly function  continuously
@ 2010-03-31 14:18 spark.z
  2010-03-31 14:56 ` Cedric Roux
  2010-04-07 14:46 ` Ian Lance Taylor
  0 siblings, 2 replies; 9+ messages in thread
From: spark.z @ 2010-03-31 14:18 UTC (permalink / raw)
  To: gcc-help


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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-04-08 13:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-31 14:18 Help! Program crashed when call the inline assembly function continuously spark.z
2010-03-31 14:56 ` Cedric Roux
2010-03-31 21:24   ` spark.z
2010-04-01  8:40     ` Cedric Roux
2010-04-01 13:38       ` spark.z
2010-04-01 13:52         ` Cedric Roux
2010-04-08 13:01           ` spark.z
2010-04-07 14:46 ` Ian Lance Taylor
2010-04-08 13:04   ` spark.z

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).