๐ -> Stack and Assembly
๐ค Vocab
โ Unit and Larger Context
To call a function, push args to stack in reverse order
fun (a,b,c): push c, push b, push a
โ๏ธ -> Scratch Notes
movl 8(%ebp), %eax //move 8 bytes past ebp into eax
addl $1, eax // eax += 1
// pushing printf("boo %d\n", a)
~push a
~push pointer to string "boo %d\n"
Prologue
Def
- Establish the stack frame for the current function
- EBP holds the pointer to the start of the stack frame
- Stack frame is everything between EBP and ESP
- The stack frame gives you a fixed location for accessing locals and arguments
- ESP keeps changing throughout the runtime of your function so it makes really hard to keep accessing locals and args through it because it keeps changing
Execution
- Save the old stack fgrame. stack frames are tracked by EBP //Push %ebp
- Establish the new stack frame // Movl %esp, %ebp
- Make space for locals // Subl $num_locals * ws, %esp
- Save any other registers aside from EAX, ECX, and EDX you plan on using // push those registers
Epilogue
Undoes the prologue
- Restore saved registers // pop the saved registers off the stack or move them off the stack
- Remove the locals // movl %ebp, %esp
- Restore the old stack frame // pop %ebp
Leal
LEAA = Load Effective Address
Most commonly used for the address of operator, &, and pointer arithmetic
๐งช-> Example
- List examples of where entry contents can fit in a larger context
๐ -> Links
Resources
- Put useful links here
Connections
- Link all related words