Final Review Flashcards

1
Q

Which op code is used for branch instructions?

A

00

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

What is the op code for call instructions?

A

01

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

What is the op code for format 3 instructions?

A

10 and 11

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

What’s the difference between a subroutine and a leaf subroutine?

A

A leaf subroutine will have no further subroutine calls within it, and therefore we don’t need to start with a save instruction.

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

Which instruction do most subroutines start with?

A

The save instruction

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

What does the save instruction actually do?

A

It shifts the stack pointer, and therefore the frame pointer in reference to the %sp

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

What does a format 1 instruction look like?

A

01 + (displacement 30)

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

What does a format 2 branch instruction look like?

A

00 + a + cond (4-bit) + op2 (010) + 22 bit immediate

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

What does a format 2 sethi instruction look like?

A

00 + rd (5-bit) + 100 + 22 bit immediate

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

What does a format 3 instruction with two source registers look like?

A

1 x + rd (5-bit) + op3 (6-bit) + rs1 (5-bit) + 0 + 0’s (8-bit) + rs2 (5-bit)

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

What does a format 3 instruction with one source register and an immediate constant look like?

A

1 x + rd (5-bit) + op3 (6-bit) + rs1 (5-bit) + 1 + 13-bit immediate constant

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

If you wanted to save n (a 32-bit int) into the %o0 register, what two lines of code would you use?

A

sethi n&raquo_space; 10, %o0

or %o0, n & 0x3ff, %o0

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

If you want to save n (a 32-bit int) into %o0 using the hi and lo instructions, what would that look like?

A

sethi %hi(n), %o0

or %o0, %lo(n), %o0

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

What is the synthetic instruction that combines the “sethi” and “or” instruction to store n in %o0?

A

set n, %o0

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

What is an open subroutine?

A

A piece of code that has been defined, that we do not jump via memory to, but that expands every time it’s called

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

What is a closed subroutine?

A

Code that we branch to whenever we want to use it, and then return to the next instruction immediately after the branch

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

Define:

endian

A

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

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

Is SPARC big or little endian?

A

SPARC is big-endian

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

How would you access the i-th element in a one-dimensional array?

A

address_of_first_element + i * size_of_element_in_bytes

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

Use the var macro to do the following:

int a[100]

A

var(a, 4, 4*100)

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

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?)

A

sll %i_r, 2, %o0 !o0 = i * 4
add %fp, %o0, %o0 !o0 = %fp + i * 4
ld [%o0 + a], %o0

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

What does the save instruction do to the registers?

A

It changes the register mapping so that new registers are provided

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

What does the restore instruction do?

A

It restores the register mapping on subroutine return

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

What is the stack pointer?

A

<p>It points to the top of the stack, that is, last occupied stack memory element</p>

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

What register is used for %sp?

A

<p>%o6</p>

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

Which register is used for %fp?

A

<p>%i6</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
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
30
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
31
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
32
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
33
Q

<p>How does the code work for chopping?</p>

A

<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 "&amp; -8"</p>

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

<p>What does the save instruction do?</p>

A

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

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

<p>How does the ifelse macro work?</p>

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
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
39
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.

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

<p>Which condition codes:

| bl</p>

A

<p>(N xor V) = 1</p>

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

<p>Which condition codes:

| ble</p>

A

<p>Z or (N xor V) = 1</p>

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

Which condition codes:be

A

Z = 1

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

<p>Which condition codes:

| bne</p>

A

<p>Z = 0</p>

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

<p>Which condition codes:

| bge</p>

A

<p>(N xor V) = 0</p>

45
Q

<p>Which condition codes:

| bg</p>

A

<p>Z or (N xor V) = 0</p>

46
Q

Which condition codes are used with signed branches?

A

N, V, and Z

47
Q

Which condition codes are used with unsigned branches?

A

C and Z

48
Q

<p>Which condition codes:

| blu</p>

A

<p>C = 1</p>

49
Q

<p>Which condition codes:

| bleu</p>

A

<p>C or Z = 1</p>

50
Q

<p>Which condition codes:

| bgeu</p>

A

<p>C or Z = 0</p>

51
Q

<p>Which condition codes:

| bgu</p>

A

<p>C = 0</p>

52
Q

<p>Which condition codes:

| bneg</p>

A

<p>N = 1</p>

53
Q

Which condition codes:bpos

A

N = 0

54
Q

Which condition codes:bz

A

Z = 1(be)

55
Q

<p>Which condition codes:

| bnz</p>

A

<p>Z = 0

| (bne)</p>

56
Q

Which condition codes:bvs

A

V = 1

57
Q

<p>Which condition codes:

| bvc</p>

A

<p>V = 0</p>

58
Q

Which condition codes:bcs

A

C = 1(blu)

59
Q

<p>Which condition codes:

| bcc</p>

A

<p>C = 0

| (bgeu)</p>

60
Q

What are the four condition codes?

A

N: negative
Z: zero
C: carry-out
V: overflow

61
Q

The manipulation of the symbols that represent numeric codes is facilitated by what?

A

A macro processor

62
Q

What is m4?

A

The UNIX macro processor.

63
Q

Define “accumulator”

A

An accumulator is a register used to contain the results of an arithmetical or logical operation

64
Q

Define “register”

A

A location in a store of data, used for a specific purpose and with quick access time

65
Q

What is a stack?

A

A stack is a first-in-last-out data structure in which only the top stack elements are accessible

66
Q

What is the ALU?

A

The arithmetic logic unit. The unit in a computer that carries out arithmetical and/or logical operations

67
Q

Stacks and registers are two forms of what?

A

Memory

68
Q

Why would one use a register instead of the stack?

A

Registers are useful when values enter into the computation in a less structured manner

69
Q

In a computer, what is an “address”?

A

A location in memory

70
Q

What does the program counter do?

A

It keeps track of the address of the next instruction to be executed

71
Q

What is assembly language?

A

Symbols representing numeric values

72
Q

Define “macro”.

A

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.

73
Q

How many arguments can a macro take?

A

A macro can have up to nine arguments

74
Q

If there are arguments present with a macro, how does the processor handle them?

A

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.

75
Q

What is a location counter?

A

It is a symbol representing the memory address of the instruction being assembled.

76
Q

What is “eval”?

A

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.

77
Q

What is a macro processor?

A

Identifies macro tokens and arguments in its input stream, and substitutes the macro definitions in their place to be rescanned

78
Q

Define “define” in m4

A

A built in macro that defines its first argument to be a macro token to be replaced on evaluation by its second argument

79
Q

What is an accumulator machine?

A

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.

80
Q

What is a label?

A

A symbol whose value is the address where the instruction or data it references will be located in memory

81
Q

<p>What are the four registers?</p>

A

%g for global
%o for output
%l for local
%i for input

82
Q

What is a symbol table?

A

A table of symbol-value pairs that is created by the macro processor on the first pass and utilised on the second pass

83
Q

What is MAR?

A

Memory access register

84
Q

<p>Which registers does .div work with?</p>

A

It takes what’s in %o0, divides %o1 into it, and stores the result in %o0

85
Q

What is MDR?

A

Memory data register

86
Q

What type of architecture is SPARC?

A

Load/store

87
Q

Which register does trap get its service request instruction from?

A

%g1

88
Q

Which condition code is set when the sign of the addends is the same but the sign of the result is different?

A

V (overflow)

89
Q

What type of architecture is SPARC?

A

Stack architecture

90
Q

Which register is used for the subroutine return address?

A

%i7

91
Q

Which condition code is set when the sign of the addends is the same but the sign of the result is different?

A

V (overflow)

92
Q

What does CISC stand for?

A

Complex instruction set computing

93
Q

Which register is used for the subroutine return address?

A

%i7

94
Q

Which formula is used to find a negative number in diminished radix complement?

A

r^n - 1 - b

95
Q

What does CISC stand for?

A

Complex instruction set computing

96
Q

Which formula is used to find a negative number in radix complement?

A

r^n - 1 - b + 1

97
Q

Which formula is used to find a negative number in diminished radix complement?

A

r^n - 1 - b

98
Q

Which shift corresponds to multiplication by two?

A

sll (shift left logical)

99
Q

Why does mulscc set the N and V condition codes?

A

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

100
Q

What would your save instruction be if you wanted to have room for 5 int vars on the stack?

A

save %sp, (-92 - (5 * 4)) & -8, %sp

101
Q

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]

A

%fp + arr + (i * dj * dk * 4) + (j * dk * 4) + (k * 4)

102
Q

Why does mulscc set the N and V condition codes?

A

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

103
Q

What would your save instruction be if you wanted to have room for 5 int vars on the stack?

A

save %sp, (-92 - (5 * 4)) & -8, %sp

104
Q

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]

A

%fp + arr + (i * dj * dk * 4) + (j * dk * 4) + (k * 4)

105
Q

call %o0

is a synthetic instruction for which code?

A

jmpl %o0, %o7

106
Q

What is the “ret” instruction a synthetic instruction for?

A

jmpl %i7 + 8, %g0

107
Q

How do we return from a leaf subroutine?

A

retl

108
Q

How to we return from a non-leaf subroutine?

A

ret

restore