title: Exit program x86
body: <p>I am learning x86 assembly. I am trying to understand how "exiting program" works on x86. We have a code :</p>
  
  <pre><code>push ebp
  mov ebp,esp
  //Some stuff here
  mov esp, ebp
  pop ebp
  ret
  </code></pre>
  
  <p>When processor executes instruction "ret" :</p>
  
  <p>EIP will have value, which is popped from stack, in other words 0.
  so processor will go to 0 address and will try to execute instructions ... which doesn't contain program code/executable code.
  So, what is really going on with processor? Are there condition check, for example, <code>if EIP = 0 -&gt; exit program?</code> <code>Or if ESP out of bounds -&gt; exit program?</code> `How processor understands that <strong>this RET instruction</strong> is the end of the program?</p>