title: Adding values in C using inline assembly
body: <p>Im trying to get a grasp on the basics of inline assembly in C (ATT assembly), so Im practicing by adding 2 variables.</p>
  
  <p>Ok so this works as intended; the <em>src</em> variable gets copied to the <em>dst</em> variable and then the <em>dst</em> variable gets added by 5. The values of <em>src</em> and <em>dst</em> are 1 and 6 respectively.</p>
  
  <pre><code>int src = 1;
  int dst = 0;
  
  asm ("mov %[SRC], %[DEST]\n\t"
       "add $5, %0"
       : [DEST] "=r" (dst));
       : [SRC] "r" (src));
  </code></pre>
  
  <p>But when I try this out, the values of <em>src</em> and <em>dst</em> are still 1 and 6. I was expecting <em>src</em> to have the value 1 and <em>dst</em> to have the value 5 since adding 5 to <em>dst</em> (which has the value of 0 since the MOV operation has been removed) should have the output 5.  </p>
  
  <p>int src = 1;
     int dst = 0;</p>
  
  <pre><code> asm ("add $5, %[DEST]"
       : [DEST] "=r" (dst)
       : [SRC] "r" (src));
  </code></pre>
  
  <p>So I then try removing the <em>src</em> as an input operand using the following code, but now <em>dst</em> gets the value 11.</p>
  
  <pre><code>int dst = 0;
  
       asm (
           "add $5, %[DEST]"
           : [DEST] "=r" (dst));
  </code></pre>
  
  <p>Now I'm a bit confused how it works. What am I misunderstanding?</p>