Chapter 5 Flashcards

1
Q

What is the stack pointer?

A

It points to the top of the stack, that is, last occupied stack memory element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the frame pointer?

A

It holds a stored copy of the stack pointer before it is changed to provide more storage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When does the frame pointer actually get moved?

A

It stays in the same place until we move the stack pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you access an item in an array?

A
  1. Get the index that you’re looking to access
  2. Multiply the index by the element size (the size of the variable type)
  3. Add the frame pointer to the address of the array
  4. Add the multiplied index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What register is used for %sp?

A

%o6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which register is used for %fp?

A

%i6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between “the stack” and a stack machine?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does the stack work with memory allocation, and how does it grow?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do we keep the %sp double word aligned?

A

By making sure it’s divisible by 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How much memory do we need for our registers?

A

92 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does the code work for chopping?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does chopping work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the save instruction do?

A

The save instruction both performs addition and saves the content of the stack pointer is %fp.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the six load instructions?

A

ldsb: load signed byte
ldub: load unsigned byte
ldsh: load signed halfword
lduh: load unsigned halfword
ld: load
ldd: load double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If you wanted to load a first variable, called a0, into %l1, what instruction would you use?

A

ld [%fp - 4] %l1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If you wanted to load a first variable, called a1, into %l1, what instruction would you use?

A

ld [%fp-4] %l1

17
Q

How would you store a new value back into the first variable from %l3?

A

st %l3 [%fp - 4]

18
Q

How does the ifelse macro work?

A

It takes four arguments. It compares the first two: if they are equal, it returns the third argument. Otherwise, it returns the 4th.