๐Ÿ“— -> Stack and Assembly


Lecture Slide Link

๐ŸŽค 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

  1. Save the old stack fgrame. stack frames are tracked by EBP //Push %ebp
  2. Establish the new stack frame // Movl %esp, %ebp
  3. Make space for locals // Subl $num_locals * ws, %esp
  4. Save any other registers aside from EAX, ECX, and EDX you plan on using // push those registers

Epilogue

Undoes the prologue

  1. Restore saved registers // pop the saved registers off the stack or move them off the stack
  2. Remove the locals // movl %ebp, %esp
  3. 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

Resources

  • Put useful links here

Connections

  • Link all related words