Chapter 5 Flashcards
What is the stack pointer?
It points to the top of the stack, that is, last occupied stack memory element
What is the frame pointer?
It holds a stored copy of the stack pointer before it is changed to provide more storage
When does the frame pointer actually get moved?
It stays in the same place until we move the stack pointer
How do you access an item in an array?
- Get the index that you’re looking to access
- Multiply the index by the element size (the size of the variable type)
- Add the frame pointer to the address of the array
- Add the multiplied index
What register is used for %sp?
%o6
Which register is used for %fp?
%i6
What is the difference between “the stack” and a stack machine?
Although they are both first-in-last-out data structures, a stack machines uses popping and pushing to perform arithmetic and logical operations on the top two items. The stack does not.
How does the stack work with memory allocation, and how does it grow?
It grows downwards from the top of memory. When we allocate space for our use, we subtract from the stack pointer, moving the %sp to a new address, and keeping the %fp at the old location of the %sp
How do we keep the %sp double word aligned?
By making sure it’s divisible by 8
How much memory do we need for our registers?
92 bytes
How does the code work for chopping?
We start with our -92 bytes for registers, subtract the amount of memory we need for any automatic variables, and then we chop it with “& -8”
How does chopping work?
Chopping is a bitwise-and operation; for example, if you wanted chop something that is halfword aligned, you perform a bitwise-and operation with the number you wish to chop (in binary) and two (in binary). The result is your halfword-aligned address
What does the save instruction do?
The save instruction both performs addition and saves the content of the stack pointer is %fp.
What are the six load instructions?
ldsb: load signed byte
ldub: load unsigned byte
ldsh: load signed halfword
lduh: load unsigned halfword
ld: load
ldd: load double
If you wanted to load a first variable, called a0, into %l1, what instruction would you use?
ld [%fp - 4] %l1