title: What is exactly the base pointer and stack pointer? To what do they point?
body: <p>Using <a href="http://en.wikipedia.org/wiki/Call_stack" rel="noreferrer">this example</a> coming from wikipedia, in which DrawSquare() calls DrawLine(),</p>
  
  <p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Call_stack_layout.svg/342px-Call_stack_layout.svg.png" alt="alt text"></p>
  
  <p>(Note that this diagram has high addresses at the bottom and low addresses at the top.)</p>
  
  <p>Could anyone explain me what <code>ebp</code> and <code>esp</code> are in this context?</p>
  
  <p>From what I see, I'd say the stack pointer points always to the top of the stack, and the base pointer to the beginning of the the current function? Or what?</p>
  
  <hr>
  
  <p>edit: I mean this in the context of windows programs</p>
  
  <p><strong>edit2: And how does <code>eip</code> work, too?</strong></p>
  
  <p><strong>edit3:</strong> I have the following code from MSVC++:</p>
  
  <pre><code>var_C= dword ptr -0Ch
  var_8= dword ptr -8
  var_4= dword ptr -4
  hInstance= dword ptr  8
  hPrevInstance= dword ptr  0Ch
  lpCmdLine= dword ptr  10h
  nShowCmd= dword ptr  14h
  </code></pre>
  
  <p>All of them seem to be dwords, thus taking 4 bytes each. So I can see there is a gap from hInstance to var_4 of 4 bytes. What are they? I assume it is the return address, as can be seen in wikipedia's picture?</p>
  
  <hr>
  
  <p>(editor's note: removed a long quote from Michael's answer, which doesn't belong in the question, but a followup question was edited in):</p>
  
  <p>This is because the flow of the function call is:</p>
  
  <pre><code>* Push parameters (hInstance, etc.)
  * Call function, which pushes return address
  * Push ebp
  * Allocate space for locals
  </code></pre>
  
  <p><strong>My question (last, i hope!) now is, what is exactly what happens from the instant I pop the arguments of the function i want to call up to the end of the prolog? I want to know how the ebp, esp evolve during those moments(I already understood how the prolog works, I just want to know what is happening after i pushed the arguments on the stack and before the prolog).</strong></p>