title: X86 assembly - Handling array-type parameters
body: <p>I am currently writing a simple C compiler, that takes a .c file as input and generates assembly code (X86, AT&amp;T syntax). I am having a hard time passing array-type parameters and generating the correct assembly code for it. Here's my input:</p>
  
  <pre><code>int getIndexOne(int tab[]){
    return tab[1];
  }
  
  int main_test(void){
    int t[3];
    t[0] = 0;
    t[1] = 1;
    t[2] = 2;
    return getIndexOne(t);
  }
  </code></pre>
  
  <p>A fairly simple test. Here is my output:</p>
  
  <pre><code>getIndexOne:
  .LFB0:
      .cfi_startproc
      pushl   %ebp
      .cfi_def_cfa_offset 16
      movl    %esp, %ebp
      .cfi_offset 6, -16
      .cfi_def_cfa_register 6
      movl    %edi, -24(%ebp)
      movl    $1, %eax
      movl    -24(%ebp, %eax, 8), %eax    #trouble over here
      leave
      .cfi_def_cfa 7, 8
      ret
      .cfi_endproc
  .LFE0:
      .size getIndexOne, .-getIndexOne
  
  
  falsemain:
  .LFB1:
      .cfi_startproc
      pushl   %ebp
      .cfi_def_cfa_offset 16
      movl    %esp, %ebp
      .cfi_offset 6, -16
      .cfi_def_cfa_register 6
      pushl   %ebx
      subl    $120, %esp
      movl    $2, -32(%ebp)
      movl    $0, %eax
      movl    $0, -24(%ebp, %eax, 8)
      movl    $1, %eax
      movl    $1, -24(%ebp, %eax, 8)
      movl    $2, %eax
      movl    $2, -24(%ebp, %eax, 8)
      leal    -24(%ebp, %eax, 8), %eax
      movl    %eax, %edi
      call    getIndexOne
      addl    $120, %esp
      popl    %ebx
      leave
      .cfi_def_cfa 7, 8
      ret
      .cfi_endproc
  .LFE1:
      .size main_test, .-main_test
  </code></pre>
  
  <p>I'm unable to access the content of the passed address (leal instruction). Any help would be much appreciated.
  PS: Don't worry about the size of my ints, they are set to 8 instead of 4 bytes for other reasons.</p>