title: In assembly, how to add integers without destroying either operand?
body: <p>Using AT&amp;T syntax on x86-64, I wish to assemble <code>c = a + b;</code> as</p>
  <pre><code>add %[a], %[b], %[c]
  </code></pre>
  <p>Unfortunately, GNU's assembler will not do it.  Why not?</p>
  <p><strong>DETAILS</strong></p>
  <p>According to Intel's <em>Software Developer's Manual,</em> rev. 75 (June 2021), vol. 2, section 2.5,</p>
  <blockquote>
  <p>VEX-encoded general-purpose-register instructions have ... instruction syntax support for three encodable operands.</p>
  </blockquote>
  <p>The VEX prefix is an AVX feature, so x86-64 CPUs from Sandy Bridge/Bulldozer onward implement it.  That's ten years ago, so GNU's assembler ought to assemble my three-operand instruction, oughtn't it?</p>
  <p>To clarify, I am aware that one can write it in the old style as</p>
  <pre><code>mov %[a], %[c]
  add %[b], %[c]
  </code></pre>
  <p>However, I wish to write it in the new, VEX style.  Incidentally, I have informed the assembler that I have a modern CPU by issuing GCC the <code>-march=skylake</code> command-line option.</p>
  <p>What is my mistake, please?</p>
  <p><strong>SAMPLE CODE</strong></p>
  <p>In a C++ wrapper,</p>
  <pre><code>#include &lt;cstddef&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      volatile int a{8};
      volatile int b{5};
      volatile int c{0};
      //c = a + b;
      asm volatile (
          //&quot;mov %[a], %[c]\n\t&quot;
          //&quot;add %[b], %[c]\n\t&quot;
          &quot;add %[a], %[b], %[c]\n\t&quot;
          : [c] &quot;=&amp;r&quot; (c)
          : [a] &quot;r&quot; (a), [b] &quot;r&quot; (b)
          : &quot;cc&quot;
      );
      std::cout &lt;&lt; c &lt;&lt; &quot;\n&quot;;
  }
  </code></pre>