Final Review Flashcards
Which op code is used for branch instructions?
00
What is the op code for call instructions?
01
What is the op code for format 3 instructions?
10 and 11
What’s the difference between a subroutine and a leaf subroutine?
A leaf subroutine will have no further subroutine calls within it, and therefore we don’t need to start with a save instruction.
Which instruction do most subroutines start with?
The save instruction
What does the save instruction actually do?
It shifts the stack pointer, and therefore the frame pointer in reference to the %sp
What does a format 1 instruction look like?
01 + (displacement 30)
What does a format 2 branch instruction look like?
00 + a + cond (4-bit) + op2 (010) + 22 bit immediate
What does a format 2 sethi instruction look like?
00 + rd (5-bit) + 100 + 22 bit immediate
What does a format 3 instruction with two source registers look like?
1 x + rd (5-bit) + op3 (6-bit) + rs1 (5-bit) + 0 + 0’s (8-bit) + rs2 (5-bit)
What does a format 3 instruction with one source register and an immediate constant look like?
1 x + rd (5-bit) + op3 (6-bit) + rs1 (5-bit) + 1 + 13-bit immediate constant
If you wanted to save n (a 32-bit int) into the %o0 register, what two lines of code would you use?
sethi n»_space; 10, %o0
or %o0, n & 0x3ff, %o0
If you want to save n (a 32-bit int) into %o0 using the hi and lo instructions, what would that look like?
sethi %hi(n), %o0
or %o0, %lo(n), %o0
What is the synthetic instruction that combines the “sethi” and “or” instruction to store n in %o0?
set n, %o0
What is an open subroutine?
A piece of code that has been defined, that we do not jump via memory to, but that expands every time it’s called
What is a closed subroutine?
Code that we branch to whenever we want to use it, and then return to the next instruction immediately after the branch
Define:
endian
Relating to a system of ordering data in a computer’s memory, where the most significant (big-endian) or least significant (little-endian) byte is put first
Is SPARC big or little endian?
SPARC is big-endian
How would you access the i-th element in a one-dimensional array?
address_of_first_element + i * size_of_element_in_bytes
Use the var macro to do the following:
int a[100]
var(a, 4, 4*100)
How would you access the i-th element from:
var(a, 4, 4*100),
and store the result into %o0?
(i.e. what three instructions do you need?)
sll %i_r, 2, %o0 !o0 = i * 4
add %fp, %o0, %o0 !o0 = %fp + i * 4
ld [%o0 + a], %o0
What does the save instruction do to the registers?
It changes the register mapping so that new registers are provided
What does the restore instruction do?
It restores the register mapping on subroutine return
What is the stack pointer?
<p>It points to the top of the stack, that is, last occupied stack memory element</p>
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
What register is used for %sp?
<p>%o6</p>
Which register is used for %fp?
<p>%i6</p>
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
<p>How does the code work for chopping?</p>
<p>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"</p>
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
<p>What does the save instruction do?</p>
The save instruction both performs addition and saves the content of the stack pointer in %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
<p>How does the ifelse macro work?</p>
It takes four arguments. It compares the first two: if they are equal, it returns the third argument. Otherwise, it returns the 4th.
If you wanted to load a first variable, called a0, into %l1, what instruction would you use?
ld [%fp - 4] %l1
How does the ifelse macro work?
It takes four arguments. It compares the first two: if they are equal, it returns the third argument. Otherwise, it returns the 4th.
<p>Which condition codes:
| bl</p>
<p>(N xor V) = 1</p>
<p>Which condition codes:
| ble</p>
<p>Z or (N xor V) = 1</p>
Which condition codes:be
Z = 1
<p>Which condition codes:
| bne</p>
<p>Z = 0</p>