title: GCC extended asm, struct element offset encoding
body: <p>I am trying to write a small piece of my code in GCC style extended asm (x86-64 target) and am having trouble encoding struct offsets.</p>
  
  <p>I have a <code>struct s</code> with a member <code>size_t a[]</code>, a pointer to such a struct and an index both of which are generated within the asm block.</p>
  
  <p>Now I need to address that element in asm</p>
  
  <pre><code>asm (
      "mov %[displ](%[s], %[index], 8), %%rbx"
      : [s] "+r" (s)
      , [index] "+r" (i)
      : "memory", "cc", "rax", "rbx"
  );
  </code></pre>
  
  <p>How can I encode <code>displ</code> into the asm block? Passing <code>offsetof(struct s, a)</code> as an immediate prefixes it with <code>$</code> and generates invalid assembly.</p>
  
  <pre><code>asm (
      "mov %[displ](%[s], %[index], 8), %%rbx"
      : [s] "+r" (s)
      , [index] "+r" (i)
      : [displ] "i" (offsetof(struct s, a))
      : "memory", "cc", "rax", "rbx"
  );
  </code></pre>