This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Help! Program crashed when call the inline assembly function continuously
- From: Ian Lance Taylor <iant at google dot com>
- To: "spark.z" <spark dot yj dot zhao at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 07 Apr 2010 07:45:39 -0700
- Subject: Re: Help! Program crashed when call the inline assembly function continuously
- References: <28094526.post@talk.nabble.com>
"spark.z" <spark.yj.zhao@gmail.com> writes:
> void pincrement(int* target)
> {
> __asm__ __volatile__ ("pushl %eax");
> __asm__ __volatile__ ("lock ; incl (%%eax)" ::"a"(target));
> __asm__ __volatile__ ("popl %eax");
> }
Besides all the other answers, don't write your asm code like this.
Put all the assembler code in a single asm statement rather than using
separate asm statements.
In any case the pushl and popl appear to be unnecessary here.
Also you should look into the __sync_fetch_and_add and
__sync_add_and_fetch builtin functions.
Ian