title: How to use LDR with logical shift of #2 in ARM-64?
body: <p>I am writing a few programs in ARM assembly. 
  I wanted to write equivalent of this:</p>
  
  <pre><code>int array_test(int index)
  {
      ...
      arr[0] = 3;
      arr[1] = 9;
      arr[2] = 6;
      return arr[index];
  }
  </code></pre>
  
  <p>where I want to set array values for index 0-2 and return array value at given index.</p>
  
  <p>In my program, I use</p>
  
  <p><strong>x4 = index; SP, SP#4, SP#8 = arr[0], arr[1], arr[2]; x0 = return value</strong></p>
  
  <p>To get the array element given by index, I want to multiply index by 4 (for int size) and add to SP. However, when I use</p>
  
  <pre><code>LDR x0, [SP, x4, LSL#2]     // Load to x0, (arr[index]) for return;
  </code></pre>
  
  <p>But I get this error with aarch64-linux-android-gcc:</p>
  
  <pre><code>error: expected 'lsl' or 'sxtx' with optional shift of #0 or #3
  </code></pre>
  
  <p>However, I am able to get the same with LSL followed by LDR:</p>
  
  <pre><code>LSL x4, x4, #2      // multiply index by 4 for 32-bit int
  LDR x0, [SP, x4]    // Load to x0, (arr[index]) for return;
  </code></pre>
  
  <p>Why can I not use <strong>LDR</strong> with <strong>LSL</strong> of <strong>#2</strong>? Only #0 or #3 seem to be valid.</p>
  
  <p>Thanks for the help!</p>