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]

Re: Help! Program crashed when call the inline assembly function continuously


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]