title: Tracing program in assembly.
body: <p>I'am trying to understand how a C program looks like at assembly level so i run gdb and used disassemble on main and get_input. The program is short so that i can follow it better. 
  There are 2 lines that i don't understand. First on in main() is: </p>
  
  <p><code>0x00000000004005a3 &lt;+4&gt;:  mov    $0x0,%eax</code> </p>
  
  <p>We save the old value of rbp and save current value of rsp to rbp. What is the purpose of that instruction?</p>
  
  <p>The other in get_input() is:</p>
  
  <pre><code>000000000400581 &lt;+4&gt;:   sub    $0x10,%rsp
  </code></pre>
  
  <p>Here too we start by saving old value of rbp, by pushing it to the stack. Then giving rbp the current value of rsp. Then 16 bytes are subtracted from rsp. I understand this is space allocated but why is it 16 bytes and not 8 bytes? I made the buffer 8 bytes only, what are the purpose of the other 8 bytes?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void get_input()
  {
      char buffer[8];
  
      gets(buffer);
      puts(buffer);
  }
  
  int main()
  {
      get_input();
      return 0;
  }
  </code></pre>
  
  <p>Dump of assembler code for function main:</p>
  
  <pre><code>   0x000000000040059f &lt;+0&gt;: push   %rbp
     0x00000000004005a0 &lt;+1&gt;: mov    %rsp,%rbp
     0x00000000004005a3 &lt;+4&gt;: mov    $0x0,%eax
     0x00000000004005a8 &lt;+9&gt;: callq  0x40057d &lt;get_input&gt;
     0x00000000004005ad &lt;+14&gt;:    mov    $0x0,%eax
     0x00000000004005b2 &lt;+19&gt;:    pop    %rbp
     0x00000000004005b3 &lt;+20&gt;:    retq   
  End of assembler dump.
  </code></pre>
  
  <p>Dump of assembler code for function get_input:</p>
  
  <pre><code>   0x000000000040057d &lt;+0&gt;: push   %rbp
     0x000000000040057e &lt;+1&gt;: mov    %rsp,%rbp
     0x0000000000400581 &lt;+4&gt;: sub    $0x10,%rsp
     0x0000000000400585 &lt;+8&gt;: lea    -0x10(%rbp),%rax
     0x0000000000400589 &lt;+12&gt;:    mov    %rax,%rdi
     0x000000000040058c &lt;+15&gt;:    callq  0x400480 &lt;gets@plt&gt;
     0x0000000000400591 &lt;+20&gt;:    lea    -0x10(%rbp),%rax
     0x0000000000400595 &lt;+24&gt;:    mov    %rax,%rdi
     0x0000000000400598 &lt;+27&gt;:    callq  0x400450 &lt;puts@plt&gt;
     0x000000000040059d &lt;+32&gt;:    leaveq 
     0x000000000040059e &lt;+33&gt;:    retq 
  </code></pre>