title: Strange behavior with gcc inline assembly?
body: <p>I'm new to gcc inline assembly.
  Why this code output "1" instead of "5"?</p>
  
  <p>code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  static inline int atomic_add(volatile int *mem, int add)
  {
      asm volatile(
              "lock xadd %0, (%1);"
              : "=a"(add)
              : "r"(mem), "a"(add)
              : "memory"
      );
      return add;
  }
  
  int main(void)
  {
      int a=1;
      int b=5;
      printf ( "%d\n", atomic_add(&amp;a, b) );
      return 0;
  }
  </code></pre>
  
  <p>run:</p>
  
  <pre><code>$ ./a.out
  1  # why not 5?
  </code></pre>
  
  <p>many thx. :)</p>