title: How do I refer to literal registers in gcc inline assembly in AT&T syntax?
body: <p>I am trying to refer to register literals; I need this because I want to use instructions like <code>mulx</code> which require one of their inputs to be in <code>rdx</code>.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  
  int main() {
    uint64_t x = 15, y = 3, z, w;
    asm ("mov %[x], rdx\t\n"
         "mulx %[y], %[z], %[w]\t\n"
         : [z] "=&amp;r" (z), [w] "=&amp;r" (w)
         : [x] "r" (x), [y] "r" (y)
         : "rdx"
         );
    return z + w;
  }
  </code></pre>
  
  <p>which only works with <code>-masm=intel</code> and otherwise gives </p>
  
  <pre>
  $ gcc  foo.c
  /tmp/ccGealWM.o: In function `main':
  foo.c:(.text+0x20): undefined reference to `rdx'
  collect2: error: ld returned 1 exit status
  </pre>
  
  <p>and I've tried</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  
  int main() {
    uint64_t x = 15, y = 3, z, w;
    asm ("mov %[x], %rdx\t\n"
         "mulx %[y], %[z], %[w]\t\n"
         : [z] "=&amp;r" (z), [w] "=&amp;r" (w)
         : [x] "r" (x), [y] "r" (y)
         : "rdx"
         );
    return z + w;
  }
  </code></pre>
  
  <p>which gives</p>
  
  <pre>
  $ gcc  foo.c
  foo.c: In function ‘main’:
  foo.c:5:7: error: invalid 'asm': operand number missing after %-letter
         asm ("mov %[x], %rdx\t\n"
         ^
  </pre>