How does a function call work?
<p>I am thinking about how a function call works in assembler.
Currently I think it works like:</p>

<pre><code>push arguments on stack
push eip register on stack and setting new eip value over jump  # call instruction

# callee's code
push ebp register on stack
working in the function
returning from function
pop ebp
pop eip       # ret instruction
</code></pre>

<p>so but now I am thinking about it, how does assembler save the current stack pointer?</p>

<p>For example if I have some local variables the esp(stack pointer) goes down and if I come back to the main function assembler has to set the esp pointer to the right place but how does this work ? </p>