Function prologue and epilogue

These differences are acceptable, as long as the programmer or compiler uses the stack in the correct way inside the function.

As an example, here is a typical x86 assembly language function prologue as produced by the GCC The N immediate value is the number of bytes reserved on the stack for local use.

These prologues push several base/frame pointers to allow for nested functions, as required by languages such as Pascal.

It typically does the following actions (this procedure may differ from one architecture to another): The given epilogue will reverse the effects of either of the above prologues (either the full one, or the one which uses enter).

Therefore, programmers or compilers often use the combination of leave and ret to exit the function at any point.