title: Why should you keep ESP in EBP inside a call?
body: <p>I'm reading in <a href="https://rads.stackoverflow.com/amzn/click/com/0764579010" rel="nofollow noreferrer" rel="nofollow noreferrer">Professional Assembly Language</a> by <a href="http://www.amazon.com/Richard-Blum/e/B001IODOO6/ref=ntt_athr_dp_pel_1" rel="nofollow noreferrer">Richard Blum</a> that when you enter a call you should copy the value of the <code>ESP</code> register to <code>EBP</code>, and he also provided the following template:</p>
  
  <pre><code>function_label:
      pushl %ebp
      movl %esp, %ebp
      &lt; normal function code goes here&gt;
      movl %ebp, %esp
      popl %ebp
      ret
  </code></pre>
  
  <p>I don't understand why this is necessary. When you push something inside the function, you obviously intend to pop it back, thus restoring <code>ESP</code> to it's original value.</p>
  
  <p>So why have this template?<br />
  And what's the use of the <code>EBP</code> register anyway?</p>
  
  <p>I'm obviously missing something, but what is it?</p>