title: What does subl do here?
body: <p>So... I'm compiling into assembler, with gcc -S -O2 -m32:</p>
  
  <pre><code>void h(int y){int x; x=y+1; f(y); f(2); }
  </code></pre>
  
  <p>And it gives me the following:</p>
  
  <pre><code>.file   "sample.c"
  .text
  .p2align 4,,15
  .globl h
  .type   h, @function
   h:
  pushl   %ebp
  movl    %esp, %ebp
  subl    $24, %esp
  movl    8(%ebp), %eax
  movl    %eax, (%esp)
  call    f
  movl    $2, 8(%ebp)
  leave
  jmp f
  .size   h, .-h
  .ident  "GCC: (GNU) 4.4.3 20100127 (Red Hat 4.4.3-4)"
  .section    .note.GNU-stack,"",@progbits
  </code></pre>
  
  <p>Now I know what pushl and movel: they store the current frame pointer onto the stack and then set the value of the frame pointer register to the value of the Stack Pointer.</p>
  
  <ol>
  <li>But I have no idea what the <strong>subl $24, %esp</strong> is. I understood that it moves the stack pointer down by 24 bytes. Correct?</li>
  <li>What is immed by the way?</li>
  <li>Why does <strong>movl 8(%ebp), %eax</strong>  use 8? Is it 8 bytes? Is this to accommodate for return value + argument <strong>y</strong> to h? Or am I completely off here. So this means look back 8 bytes from the stack pointer?</li>
  <li>What does <strong>movl $2, 8(%ebp)</strong> do? It copies contant 2 to the location 8 bytes before the frame pointer. Did the frame pointer change when we called f? If yes - then 8(%ebp) points to the argument location for f.</li>
  <li>What does leave do? How can it "remove" a stack frame? I mean you cant just remove a piece of memory. In the doc it says it does <strong>mov(esp, ebp), pop ebp</strong>.</li>
  </ol>
  
  <p>Thanks!</p>