Stack Memory for myFunc

This is just before the call opcode is invoked.


value of rdi← rsp
To higher addresses  
(to 0xffffffff)  
  
  
  
To lower addresses  
(to 0x00000000)  
  

Stack Memory for myFunc

This is just after the call opcode is invoked.


value of rdi 
To higher addressesreturn address← rsp
(to 0xffffffff)  
  
  
  
To lower addresses  
(to 0x00000000)  
  

Callee Rules (Prologue)

  1. Save callee-save registers
    • rbx, rbp, r12-r15
    • only need to do this if callee intends to use them, otherwise, no need to save their contents

 

THEN, perform body of the function

Stack Memory for myFunc

This is just after the caller invokes the call opcode.


value of rdi 
To higher addressesreturn address← rsp
(to 0xffffffff)  
  
  
  
To lower addresses  
(to 0x00000000)  
  

Stack Memory for myFunc

This is just after the callee invokes sub rsp, 8


value of rdi 
To higher addressesreturn address 
(to 0xffffffff)local var (result)← rsp
  
  
  
To lower addresses  
(to 0x00000000)  
  

Stack Memory for myFunc

This is after the myFunc() prologue is completed.


value of rdi 
To higher addressesreturn address 
(to 0xffffffff)local var (result)← [rsp+16]
value of rbx← [rsp+8]
value of rbp← [rsp]
  
To lower addresses  
(to 0x00000000)  
  
Code
sub rsp, 8
push rbx
push rbp
mov rax, rdi
mov rbp, rsi
mov rbx, rdx
mov [rsp+16], rbx
add [rsp+16], rbp
mov rax, [rsp+16]
pop rbp
pop rbx
add rsp, 8
ret

Callee Animation

   
StackRegisters
cc animation cc animation cc animation cc animation cc animation cc animation
cc animation cc animation cc animation cc animation cc animation cc animation cc animation cc animation
cc animation cc animation cc animation cc animation cc animation cc animation cc animation
virtual memory