Final Review Flashcards
(108 cards)
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>
%o6
%i6
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"
What does the save instruction do?
How does the ifelse macro work?
Which condition codes: | bl
(N xor V) = 1
Which condition codes: | ble
Z or (N xor V) = 1
Which condition codes: | bne
Z = 0
Which condition codes: | bge
(N xor V) = 0
Which condition codes: | bg
Z or (N xor V) = 0
Which condition codes: | blu
C = 1
Which condition codes: | bleu
C or Z = 1
Which condition codes: | bgeu
C or Z = 0
Which condition codes: | bgu
C = 0
Which condition codes: | bneg
N = 1
Which condition codes: | bnz
Z = 0 | (bne)
Which condition codes: | bvc
V = 0
Which condition codes: | bcc
C = 0 | (bgeu)
What are the four registers?
Which registers does .div work with?