title: Memory addressing with a variable for the (1,2,4,8) size
body: <p>I have a function where I'd like to pass it the starting address of a list/array as well as the element size and it to return the size. Something like, in pseudo-code:</p>
  <pre><code>int size(*start_addr, int (1,2,4 or 8) elem_size)
  </code></pre>
  <p>And in assembly to be able to run a loop that contains the following instruction:</p>
  <pre><code>mov (%edi, %eax, 4), %r8d
  </code></pre>
  <p>However, I want to be able to use the <code>elem_size</code> instead of the hardcoded <code>4</code>. is it possible to pass a register such as:</p>
  <pre><code>mov (%edi, %eax, &quot; value in %esi &quot;), %r8d
  </code></pre>
  <p>If not, what might be the best way to get around this? (I was thinking about passing it an offset with the <code>size * index</code> offset as another register and removing the 1/2/4/8 <code>size</code> part).</p>