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>
<p>Which condition codes:
| bge</p>
<p>(N xor V) = 0</p>
<p>Which condition codes:
| bg</p>
<p>Z or (N xor V) = 0</p>
Which condition codes are used with signed branches?
N, V, and Z
Which condition codes are used with unsigned branches?
C and Z
<p>Which condition codes:
| blu</p>
<p>C = 1</p>
<p>Which condition codes:
| bleu</p>
<p>C or Z = 1</p>
<p>Which condition codes:
| bgeu</p>
<p>C or Z = 0</p>
<p>Which condition codes:
| bgu</p>
<p>C = 0</p>
<p>Which condition codes:
| bneg</p>
<p>N = 1</p>
Which condition codes:bpos
N = 0
Which condition codes:bz
Z = 1(be)
<p>Which condition codes:
| bnz</p>
<p>Z = 0
| (bne)</p>
Which condition codes:bvs
V = 1
<p>Which condition codes:
| bvc</p>
<p>V = 0</p>
Which condition codes:bcs
C = 1(blu)
<p>Which condition codes:
| bcc</p>
<p>C = 0
| (bgeu)</p>
What are the four condition codes?
N: negative
Z: zero
C: carry-out
V: overflow
The manipulation of the symbols that represent numeric codes is facilitated by what?
A macro processor
What is m4?
The UNIX macro processor.
Define “accumulator”
An accumulator is a register used to contain the results of an arithmetical or logical operation
Define “register”
A location in a store of data, used for a specific purpose and with quick access time
What is a stack?
A stack is a first-in-last-out data structure in which only the top stack elements are accessible
What is the ALU?
The arithmetic logic unit. The unit in a computer that carries out arithmetical and/or logical operations
Stacks and registers are two forms of what?
Memory
Why would one use a register instead of the stack?
Registers are useful when values enter into the computation in a less structured manner
In a computer, what is an “address”?
A location in memory
What does the program counter do?
It keeps track of the address of the next instruction to be executed
What is assembly language?
Symbols representing numeric values
Define “macro”.
Symbol, name, or key that represents a list of commands, actions, or keystrokes. Many programs allow you to create macros so that you can enter a single character or word to perform a whole series of actions.
How many arguments can a macro take?
A macro can have up to nine arguments
If there are arguments present with a macro, how does the processor handle them?
The arguments are evaluated; if they are in quotes, the quotes are stripped and the arguments are NOT evaluated; any $n subs are made. The macro is fully expanded and pushed back to output stream.
What is a location counter?
It is a symbol representing the memory address of the instruction being assembled.
What is “eval”?
It’s a built in macro that takes in a string argument to represent an arithmetic expression. It then evaluates the expression and returns its value in the form of a numerical string.
What is a macro processor?
Identifies macro tokens and arguments in its input stream, and substitutes the macro definitions in their place to be rescanned
Define “define” in m4
A built in macro that defines its first argument to be a macro token to be replaced on evaluation by its second argument
What is an accumulator machine?
It combines an operand from memory with the contents of a single register (the accumulator) and stores the result of the operation in the accumulator. The contents of the accumulator can be loaded from and stored into memory.
What is a label?
A symbol whose value is the address where the instruction or data it references will be located in memory
<p>What are the four registers?</p>
%g for global
%o for output
%l for local
%i for input
What is a symbol table?
A table of symbol-value pairs that is created by the macro processor on the first pass and utilised on the second pass
What is MAR?
Memory access register
<p>Which registers does .div work with?</p>
It takes what’s in %o0, divides %o1 into it, and stores the result in %o0
What is MDR?
Memory data register
What type of architecture is SPARC?
Load/store
Which register does trap get its service request instruction from?
%g1
Which condition code is set when the sign of the addends is the same but the sign of the result is different?
V (overflow)
What type of architecture is SPARC?
Stack architecture
Which register is used for the subroutine return address?
%i7
Which condition code is set when the sign of the addends is the same but the sign of the result is different?
V (overflow)
What does CISC stand for?
Complex instruction set computing
Which register is used for the subroutine return address?
%i7
Which formula is used to find a negative number in diminished radix complement?
r^n - 1 - b
What does CISC stand for?
Complex instruction set computing
Which formula is used to find a negative number in radix complement?
r^n - 1 - b + 1
Which formula is used to find a negative number in diminished radix complement?
r^n - 1 - b
Which shift corresponds to multiplication by two?
sll (shift left logical)
Why does mulscc set the N and V condition codes?
It’s so that when multiplication is being done, we can test N ^ V to see if a one or zero should be shifted in
What would your save instruction be if you wanted to have room for 5 int vars on the stack?
save %sp, (-92 - (5 * 4)) & -8, %sp
What is the mapping, for row major order, of the i-th, j-th, k-th element of an array named arr?
int arr[di][dj][dk]
%fp + arr + (i * dj * dk * 4) + (j * dk * 4) + (k * 4)
Why does mulscc set the N and V condition codes?
It’s so that when multiplication is being done, we can test N ^ V to see if a one or zero should be shifted in
What would your save instruction be if you wanted to have room for 5 int vars on the stack?
save %sp, (-92 - (5 * 4)) & -8, %sp
What is the mapping, for row major order, of the i-th, j-th, k-th element of an array named arr?
int arr[di][dj][dk]
%fp + arr + (i * dj * dk * 4) + (j * dk * 4) + (k * 4)
call %o0
is a synthetic instruction for which code?
jmpl %o0, %o7
What is the “ret” instruction a synthetic instruction for?
jmpl %i7 + 8, %g0
How do we return from a leaf subroutine?
retl
How to we return from a non-leaf subroutine?
ret
restore