spark.z wrote:
The app works fine if I add the volatile prefix before the variable declaration. inline void pincrement(volatile int* target) { __asm__ __volatile__ ("pushl %%eax":::); __asm__ __volatile__ ("lock ; incl (%%eax)" :"=m"(target):"a"(target)); __asm__ __volatile__ ("popl %%eax":::"eax"); } inline void pdecrement(volatile int* target) { __asm__ __volatile__ ("pushl %%eax":::); __asm__ __volatile__ ("lock ; decl (%%eax)" :"=m"(target):"a"(target)); __asm__ __volatile__ ("popl %%eax":::"eax"); } int main() { volatile int my_an = 0; pincrement(&my_an); pincrement(&my_an); pincrement(&my_an); pdecrement(&my_an); printf("my_an is %d\n",my_an); return 0; }
try to compile like: gcc myprog.c -fomit-frame-pointer does it still work? (not for me with gcc 3.3.5, I have a segmentation fault) your "push eax" statements are not correct because you don't tell gcc they modify the stack pointer. It works because you are lucky, but your code is broken. One day or another it will crash.