title: Function prolog in terms of memory
body: <p>I'm trying to understand how function prolog work in assembly. My books shows the following code:</p>
  
  <pre><code>    push    %ebp
      movl    %ebp, %esp
  </code></pre>
  
  <p>In the definition of push it says that it decrements the value of the ESP by 4 (bytes?) and then puts the operand into the memory specified by the ESP. However won't this overwrite some data as shown in the diagram?
  <a href="https://i.stack.imgur.com/HaNLY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaNLY.png" alt="enter image description here"></a></p>
  
  <p>Also I am assuming here that each segment is 4 (bytes?) however I'm pretty sure functions can have more than 4 bytes of allocated stack space?</p>
  
  <p>Following through, the second instruction moves the contents at ESP, into EBP however what need is there for that? That is already there? And when <code>pop</code> is called how does it know how much to take away from the stack? (All of what I explained assume the fact that the instructions <code>mov</code> and <code>push</code> start from where they are pointed and go up the memory when doing any operation)</p>