3. MIPS Programming Flashcards
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
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 many programmer exposed registers does MIPS have?
32
What is the R-format of MIPS instructions?
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.
The registers $s0 through $s7 are used primarily for …..?
Program variables.
The registers $a0 through $a3 are used primarily for …..?
Arguments.
The registers $v0 and $v1 are used primarily for …..?
Values of results and expressions.
The registers $t0 through $t9 are used primarily for …..?
Temporary variables.
Give two examples of special role registers in MIPS.
Zero register, PC, stack pointer, frame pointer, global pointer, return address.
Which standard registers are preserved on call?
$s0 to $s7
What is the I-format of MIPS instructions?
opcode = 6 bits
source_reg = 5 bits
dest_reg = 5 bits
constant = 16 bits (signed)
How is a constant of more than 16 bits dealt with?
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
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.
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:
Which of the following I-format operations sign extend:
lw, addi, sw?
lw and addi
Give an advantage and a disadvantage of word alignment over unalignment.
Advantage: Coding is easier, because it is known where one word starts/ends.
Disadvantage: Extra memory is taken up in spacing out words.
Explain the terms little endian and big endian with reference to the register containing: 0A 0B 0C 0D
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)