Procedures
| CALL and RET | |
| Stack frames | |
| The calling convention |
CALL and RET
CALL pushes the return address and jumps to the procedure. RET pops the return address and jumps back to it. Together they nest calls to any depth:
call double_it
; rax now holds the result
double_it:
add rax, rax
ret
Stack frames
A procedure that needs locals builds a frame: save RBP, copy RSP into RBP, reserve space with SUB, and unwind with the mirror image in reverse:
my_proc:
push rbp
mov rbp, rsp
sub rsp, 32
; ... body ...
mov rsp, rbp ; or LEAVE
pop rbp
ret
The calling convention
On Linux x86-64 (System V ABI), integer arguments arrive in RDI, RSI, RDX, RCX, R8, R9, and the return value leaves in RAX. RBX, RBP, and R12-R15 are callee-saved: use them, but save and restore them first.
Next: LEA and addressing modes
Article author: Arthur Isaev