Data Representation  | Program Representation  | |||||
|   string int x[3] char x 0x9cd0f0ad 01101011  | 
    
    ![]()  | 
      Objects Arrays Primitive types Addresses bits  | 
      Java code C++ code C code x86 code IBCM hexadecimal  | 
    
    ![]()  | 
      High-level language Low-level language Assembly language Machine code  | 
  |
  | 
  | 
	  | 
 Directives 
 
 
  | 
 | 
  | 
 Incorrect: (why?) 
 | 
  | 
 Memory: 
  | |||||||||||||||||||||||||||||||||||||||||||||||
C/C++ code:  | 
Assembly code:  | 
This is just before the call opcode is invoked.
| ↑ | value of rdi | ← rsp | ||
| To higher addresses | ||||
| (to 0xffffffff) | ||||
| To lower addresses | ||||
| (to 0x00000000) | ||||
| ↓ | 
This is just after the call opcode is invoked.
| ↑ | value of rdi | |||
| To higher addresses | return address | ← rsp | ||
| (to 0xffffffff) | ||||
| To lower addresses | ||||
| (to 0x00000000) | ||||
| ↓ | 
THEN, perform body of the function
This is just after the caller invokes the call opcode.
| ↑ | value of rdi | |||
| To higher addresses | return address | ← rsp | ||
| (to 0xffffffff) | ||||
| To lower addresses | ||||
| (to 0x00000000) | ||||
| ↓ | 
This is just after the callee invokes the sub rsp, 8 opcode.
| ↑ | value of rdi | |||
| To higher addresses | return address | |||
| (to 0xffffffff) | local var (result) | ← rsp | ||
| To lower addresses | ||||
| (to 0x00000000) | ||||
| ↓ | 
This is after the myFunc() prologue is completed.
| ↑ | value of rdi | |||
| To higher addresses | return address | |||
| (to 0xffffffff) | local var (result) | ← [rsp+16] | ||
| value of rbx | ← [rsp+8] | |||
| value of rbp | ← [rsp] | |||
| To lower addresses | ||||
| (to 0x00000000) | ||||
| ↓ | 
	  
	  
	  
  | 
	
	  
  | 
      ||||||||||||||||||||||||||||||||||||||||
  | 
 | 
void security_hole() {
    char buffer[12];
    scanf ("%s", buffer); // how C handles input
}
The stack looks like (with sizes in parenthesis):
| rsi (8) | rdi (8) | buffer (12) | ret addr (8) |