When we make a function call, certain assembly instructions are always executed. These instructions that are executed when a function is called are called the function prologue. And, when the function exits, again certain assembly instructions are always executed. Those instructions are called the function epilogue. Enter and leave are two assembly instructions in x86 and x64 assembly that are executed every time we call a function or when the function exits.
When we call a function in x64, the RBP needs to be pushed, the content of the RSP register is then moved to the RBP register, and then, certain bytes are subtracted from the RSP register. Please note that the RBP register points to the base of the stack frame of the function. And, the RSP register points to the top of the stack frame.
In other words, the following instructions are executed every time a function call is made:
push rbp mov rbp,rsp sub rsp,N
The enter instruction in x86 and x64 assembly executes these assembly instructions. So, instead of the push, mov and sub instructions, we can use the enter assembly instruction.
enter N,0
N is the number of bytes that needs to be subtracted from the RSP register. The second parameter of the enter instruction is used for nested functions. The above instruction is equivalent to:
push rbp mov rbp,rsp sub rsp,N






0 Comments