Operating Systems 2019W Lecture 5

From Soma-notes
Revision as of 19:11, 22 January 2019 by Soma (talk | contribs) (Created page with "==Video== Video from the lecture given on January 21, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec04-20190121.m4v is now available]....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Video

Video from the lecture given on January 21, 2019 is now available.

Notes

In Class

Lecture 5
---------

Stack manipulation


FFFF


C000   <-- old %rsp 



B100  <-- enter a function X
B000  <-- start of local variables



0000

When something is "pushed" onto the stack of size n
 - end of storage is current value of %rsp
 - new top of stack is old %rsp - n
 - new variable is new %rsp, has size n



n = 16 (10 in hex)

old %rsp = C000
new %rsp = BFF0
new pointer = BFF0

call instruction pushes %rip to stack
 - causes %rsp to be decremented by 8 on x86-64
 - return address is stored at new value of %rsp

stack allocation of memory never fragments
 - because you always allocate and deallocate in the order of stack growth
   or shrinkage


When a function starts, it
 - saves stack pointer to base pointer (%rsp->%rbp)
 - saves registers to the stack
 - allocates space for local variables by decrementing the stack pointer
   (%rsp)

When a function exits, it
 - restores registers from the stack (reverse of pushing order),
   USING %rbp
 - returns, popping return address off stack