title: What's the difference between the x86-64 AT&T instructions movq and movabsq?
body: <p>After reading <a href="https://stackoverflow.com/questions/40315803/difference-between-movq-and-movabsq-in-x86-64">this stack overflow answer</a>, and <a href="https://www.cs.cmu.edu/%7Efp/courses/15213-s07/misc/asm64-handout.pdf" rel="nofollow noreferrer">this document</a>, I still don't understand the difference between <code>movq</code> and <code>movabsq</code>.</p>
  <p>My current understanding is that in <code>movabsq</code>, the first operand is a 64-bit immediate operand whereas <code>movq</code> sign-extends a 32-bit immediate operand. From the 2nd document referenced above:</p>
  <blockquote>
  <p>Moving immediate data to a 64-bit register can be done either with the <code>movq</code> instruction, which will sign extend a 32-bit immediate value, or with the <code>movabsq</code> instruction, when a full 64-bit immediate is required.</p>
  </blockquote>
  <p>In <a href="https://stackoverflow.com/questions/40315803/difference-between-movq-and-movabsq-in-x86-64">the first reference</a>, Peter states:</p>
  <blockquote>
  <p>Interesting experiment: <code>movq $0xFFFFFFFF, %rax</code> is probably not encodeable, because it's not representable with a sign-extended 32-bit immediate, and needs either the imm64 encoding or the <code>%eax</code> destination encoding.</p>
  <p>(editor's note: this mistaken assumption is fixed in the current version of that answer).</p>
  </blockquote>
  <p>However, when I assemble/run this it seems to work fine:</p>
  <pre><code>        .section .rodata
  str:
          .string &quot;0x%lx\n&quot;
          .text
          .globl  main
  main:
          pushq   %rbp
          movq    %rsp, %rbp
          movl    $str, %edi
          movq    $0xFFFFFFFF, %rsi
          xorl    %eax, %eax
          call    printf
          xorl    %eax, %eax
          popq    %rbp
          ret
  </code></pre>
  <p><code>$ clang file.s -o file &amp;&amp; ./file</code></p>
  <p>prints <code>0xffffffff</code>. (This works similarly for larger values, for instance if you throw in a few additional &quot;F&quot;s). <code>movabsq</code> generates an identical output.</p>
  <p>Is Clang inferring what I want? If it is, is there still a benefit to <code>movabsq</code> over <code>movq</code>?</p>
  <p>Did I miss something?</p>