To do this, you need to create a “naked” method using _declspec (naked) and write yourself a prologue and epilogue, which are usually created by the compiler.
The purpose of the prologue is to:
- configure EBP and ESP
- reserve stack space for local variables
- save registers that must be changed in the function body
The epilogue should:
- restore saved register values
push ebp ; Save ebp
mov ebp, esp ; Set stack frame pointer
sub esp, localbytes ; Allocate space for locals
push <registers> ; Save registers
:
pop <registers> ; Restore registers
mov esp, ebp ; Restore stack pointer
pop ebp ; Restore ebp
ret ; Return from function
(ebp - 4) (ebp - 4 - localbytes). (ebp + 8) .