title: x86_64 Inline Assembly ; Copying 64-bit register directly to 64-bit memory location
body: <p>I am running the code below and suffering from two problems:</p>
  
  <p>1) The moment I change movl (to copy values from registers) to movq I face the gcc error : <code>Error: operand size mismatch for movq</code>. In the normal assembly I see that this was possible by adding qword prefix or likes, but that also fails to satisfy gcc</p>
  
  <pre><code>uint64_t cpuid_0(uint64_t* _rax, uint64_t* _rbx, uint64_t* _rcx, uint64_t* _rdx){
  
      int a, b, c, d;
      *_rax = 0x0;
  
      __asm__
      __volatile__
      (
          "movq $0,  %%rax\n"
          "cpuid\n"
          "movl %%eax, %0\n"
          "movl %%ebx, %1\n"
          "movl %%ecx, %2\n"
          "movl %%edx, %3\n"
          : "=r" (a), "=r" (b), "=r" (c), "=r" (d)
          : "0" (a)
      );
      *_rax=a;*_rbx=b;*_rcx=c;*_rdx=d;
      return *_rax;
  }
  </code></pre>
  
  <p>2) I want to eliminate extra copy operation so I modified my code in the constraint specification:</p>
  
  <pre><code>uint64_t cpuid_0(uint64_t* _rax, uint64_t* _rbx, uint64_t* _rcx, uint64_t* _rdx){
  
      int a, b, c, d;
      *_rax = 0x0;
  
      __asm__
      __volatile__
      (
           "movq $0,  %%rax\n"
           "cpuid\n"
           "movl %%eax, %0\n"
           "movl %%ebx, %1\n"
           "movl %%ecx, %2\n"
           "movl %%edx, %3\n"
          : "+m" (*_rax), "=m" (*_rbx), "=m" (*_rcx), "=m" (_rdx)
          : "0" (*_rax)
      );
      *_rax=a;*_rbx=b;*_rcx=c;*_rdx=d;
      return *_rax;
  }
  </code></pre>
  
  <p>This gives me a host of errors like those below: </p>
  
  <pre><code>warning: matching constraint does not allow a register
  error: inconsistent operand constraints in an ‘asm’
  </code></pre>
  
  <p>Also, I assume <code>__volatile__</code> could be removed in this small code.</p>