3. MIPS Programming Flashcards

1
Q

Explain the function of the following MIPS commands:

add $t1 $t2 $t3
sub $t1 $t2 $t3

and $t1 $t2 $t3
or $t1 $t2 $t3
xor $t1 $t2 $t3

sll $t1 $t2 5
srl $t1 $t2 5
sra $t1 $t2 5

A

add: sums the values of $t2 and $t3 and stores the result in $t1
sub: subtracts the value of $t3 from $t2 and stores the result in $t1

and: performs a bitwise and operation on $t2 and $t3 and stores the result in $t1
or: performs a bitwise or operation on $t2 and $t3 and stores the result in $t1
xor: performs a bitwise xor operation on $t2 and $t3 and stores the result in $t1

sll: shifts the value of $t2 left by 5 and stores the result in $t1
srl: logically shifts the value of $t2 right by 5 and stores the result in $t1
sra: arithmetically shifts the value of $t2 right by 5 and stores the result in $t1

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

How many programmer exposed registers does MIPS have?

A

32

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

What is the R-format of MIPS instructions?

A

6 bits for main opcode.
5 bits for operand 1
5 bits for operand 2
5 bits for the result
5 bits for the shift amount
6 bits for the sub-function opcode.

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

The registers $s0 through $s7 are used primarily for …..?

A

Program variables.

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

The registers $a0 through $a3 are used primarily for …..?

A

Arguments.

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

The registers $v0 and $v1 are used primarily for …..?

A

Values of results and expressions.

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

The registers $t0 through $t9 are used primarily for …..?

A

Temporary variables.

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

Give two examples of special role registers in MIPS.

A

Zero register, PC, stack pointer, frame pointer, global pointer, return address.

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

Which standard registers are preserved on call?

A

$s0 to $s7

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

What is the I-format of MIPS instructions?

A

opcode = 6 bits
source_reg = 5 bits
dest_reg = 5 bits
constant = 16 bits (signed)

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

How is a constant of more than 16 bits dealt with?

A

The load instruction is used:

li $r1 constant is translated into:

lui $r1, constant_1 —> loads the 16-bit constant into the upper 16 bits of r1.
ori $r1, $r1, constant_2 —> bitwise or the lower 16-bits

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

Write a simple MIPS program to copy an array of size 10 beginning at the address in $s1 to an array at address stored in $s2.

A

add $t0, $t0, $zero

loop:
beq $t0, 10, end
lw $t1, 0($s1)
sw $t1, 0($s2)
addi $s1, $s1, 4
addi $s2, $s2, 4
addi $t0, $t0, 1
j loop

end:

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

Which of the following I-format operations sign extend:
lw, addi, sw?

A

lw and addi

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

Give an advantage and a disadvantage of word alignment over unalignment.

A

Advantage: Coding is easier, because it is known where one word starts/ends.
Disadvantage: Extra memory is taken up in spacing out words.

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

Explain the terms little endian and big endian with reference to the register containing: 0A 0B 0C 0D

A

In little endian, the least significant byte is stored first -> 0D 0C 0B 0A
In big endian, the most significant byte is stored last -> 0A 0B 0C 0D (MIPS)

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

Is beq R-format, I-format or J-format?

A

I-format

17
Q

What is the J-format of MIPS instructions?

A

opcode: 6 bits
pseudo-address: 26 bits

18
Q

Is slt R-format, I-format or J-format?

A

R-format

19
Q

Which is not a pseudo-instruction:
slt, sle, sgt, sge, seq, sne?

A

slt

20
Q

Describe how the jal and jr instruction works.

A

jal sets $ra to the value of $pc (as this will have already moved on by 4).
Then, $pc is set to the value of label.

jr sets $pc to the value of $ra.

21
Q

Explain how addresses for nested method calls are stored.

A

Stored as a stack in memory, starting from the top address (0x7fffffff). The stack pointer should be pointed at the lowest value of the stack address.

Push:
addi $sp, $sp, -4
sw $ra, 0($sp)

Pop:
lw $ra, 0($sp)
addi $sp, $sp, 4

21
Q

What uses does the stack have, other than to store nested method calls?

A

Saves caller’s registers, so the callee can use them.
Can pass and return parameters.
Used for local variables within the function.

22
Q

Compare CISC and RISC architectures.

A

RISC (Reduced Instruction Set Computer) is a much simpler set of instructions than CISC (Complex Instruction Set Computer).

RISC has more registers, more memory and faster clock frequencies than CISC.

23
Q

What is $at used for?

A

It’s reserved to handle large constants.

24
Q

Define ‘spilling’ in the context of registers.

A

The moving of less commonly used variables from registers to memory

25
Q

Define ‘masking’ in the context of bit manipulation.

A

AND-ing with a number with 0s in the place you don’t want, and 1s in those you do, concealing information.

26
Q

In MIPS, what instruction would perform a NOT operation on $t0 and send the result to $t1?

A

nor $t1, $t0, $zero

27
Q

Why does NOR have no immediate?

A

Constants are rare for NOR.