总结一下关于汇编函数调用过程的知识。
References:
http://www.cs.virginia.edu/~evans/cs216/guides/x86.html https://en.wikibooks.org/wiki/X86_Assembly
Before calling a subrouting, save the caller-saved registers (EAX, ECX, EDX
).
Push the parameters onto the stack.
Use call
instruction, places the retrun address onto stack, and branches to the subroutine code.
push ebp
mov ebp, esp
sub esp, 12
EBX, EDI, ESI
).Leave the return value in EAX
.
Restore the old values of any callee-saved registers (EDI, ESI, EBX
).
Deallocate local variables.
mov esp, ebp
Restore the caller’s base pointer value by poping EBP
from the stack.
Return to the caller by executing a return ret
instruction, find and reomve the return address from the stack.
Remove the parameters from stack.
Restore the contents of caller-saved registers (EAX, ECX, EDX
)