CDA 3100 CORE REVIEWS ANSWERS AND
QUESTIONS SET A+
✔✔If $t0 is holding 17, $t1 is holding 8, what will be the value stored in $t2 after the
following instructions?
andi $t0, $t0, 3
beq $t0, $0, L1
addi $t0, $t0, 1
L1: add $t2, $t0, $t1
(a) 10.
(b) 8.
(c) 2.
(d) None of the above. - ✔✔A
✔✔What does the instruction slt do?
slt $t3, $t1, $t2 - ✔✔Set $t3 to be 1 if $t1 < $t2, else clear $t3 to be 0
✔✔What register holds the address of the current instruction being executed? -
✔✔Program Counter
✔✔The offset of conditional branch instructions is relative to __________
(Slide 85, MIPS Assembly ppt) - ✔✔PC + 4
✔✔A loop must have what three things - ✔✔1. a loop body (what you want it to do)
2. A checking point
3. A mechanism to bring us from the end of the loop back to the beginning of the loop
✔✔MIPS usually ends with what instruction? - ✔✔li $v0,10 # telling the simulator to stop
syscall
✔✔If $t0 is holding 30, in the binary of instruction add $t2, $t0, $t1, the rs field should be
30? - ✔✔No; should be an index of $t0
, ✔✔Is it true that because the j instruction has to specify the entire address, it has a
smaller opcode field? - ✔✔No
✔✔Is it correct to write an instruction addi $t0, $t0, 100000? - ✔✔No, the number is too
large
✔✔Is it true that instruction beq $t0, $t1, L1 does not store the entire address
associated with L1 but the offset with respect to its own address? - ✔✔Yes
✔✔Is it true that the PC (program counter) always stores the address of the current
instruction, except when encountering beq, bne, and j? - ✔✔No
✔✔It would be nice if we have an instruction like beq $t0, 5, L1
which compares $t0 with the constant 5 and jumps if they are the same. Does MIPS
have this instruction? Why? - ✔✔Does not have it. Cannot fit in two immediate
numbers.
✔✔jal does two things: - ✔✔Goto the label in the instruction, and save the address of
the next address of the next instruction in $ra (register that stores the return address)
✔✔jr $ra does what? - ✔✔Goto the instruction whose address is the value stored in $ra
✔✔At the end of a function we write ____________ to go back - ✔✔jr $ra
✔✔T/F: A MIPS function is called by the jal instruction, which does two things: 1) going
to the address of the first instruction in the function, 2) passing the arguments in $a0 to
$a3. - ✔✔False
✔✔A MIPS function must be ended by the jr $ra instruction. - ✔✔True
✔✔MIPS functions are stored in a different part in the memory and not in the same part
as the main function. - ✔✔False
✔✔A MIPS function has to explicitly declare a name along with the list of arguments to
be passed to it, including the names and the types. - ✔✔False; No such list is explicitly
maintained.
✔✔A function in MIPS cannot have loops. - ✔✔False
✔✔In MIPS, the name of a function is a special data type. - ✔✔False
✔✔The jal L1 instruction jumps to L1, and saves the address of L1 into $ra. - ✔✔False.
The next one into $ra
QUESTIONS SET A+
✔✔If $t0 is holding 17, $t1 is holding 8, what will be the value stored in $t2 after the
following instructions?
andi $t0, $t0, 3
beq $t0, $0, L1
addi $t0, $t0, 1
L1: add $t2, $t0, $t1
(a) 10.
(b) 8.
(c) 2.
(d) None of the above. - ✔✔A
✔✔What does the instruction slt do?
slt $t3, $t1, $t2 - ✔✔Set $t3 to be 1 if $t1 < $t2, else clear $t3 to be 0
✔✔What register holds the address of the current instruction being executed? -
✔✔Program Counter
✔✔The offset of conditional branch instructions is relative to __________
(Slide 85, MIPS Assembly ppt) - ✔✔PC + 4
✔✔A loop must have what three things - ✔✔1. a loop body (what you want it to do)
2. A checking point
3. A mechanism to bring us from the end of the loop back to the beginning of the loop
✔✔MIPS usually ends with what instruction? - ✔✔li $v0,10 # telling the simulator to stop
syscall
✔✔If $t0 is holding 30, in the binary of instruction add $t2, $t0, $t1, the rs field should be
30? - ✔✔No; should be an index of $t0
, ✔✔Is it true that because the j instruction has to specify the entire address, it has a
smaller opcode field? - ✔✔No
✔✔Is it correct to write an instruction addi $t0, $t0, 100000? - ✔✔No, the number is too
large
✔✔Is it true that instruction beq $t0, $t1, L1 does not store the entire address
associated with L1 but the offset with respect to its own address? - ✔✔Yes
✔✔Is it true that the PC (program counter) always stores the address of the current
instruction, except when encountering beq, bne, and j? - ✔✔No
✔✔It would be nice if we have an instruction like beq $t0, 5, L1
which compares $t0 with the constant 5 and jumps if they are the same. Does MIPS
have this instruction? Why? - ✔✔Does not have it. Cannot fit in two immediate
numbers.
✔✔jal does two things: - ✔✔Goto the label in the instruction, and save the address of
the next address of the next instruction in $ra (register that stores the return address)
✔✔jr $ra does what? - ✔✔Goto the instruction whose address is the value stored in $ra
✔✔At the end of a function we write ____________ to go back - ✔✔jr $ra
✔✔T/F: A MIPS function is called by the jal instruction, which does two things: 1) going
to the address of the first instruction in the function, 2) passing the arguments in $a0 to
$a3. - ✔✔False
✔✔A MIPS function must be ended by the jr $ra instruction. - ✔✔True
✔✔MIPS functions are stored in a different part in the memory and not in the same part
as the main function. - ✔✔False
✔✔A MIPS function has to explicitly declare a name along with the list of arguments to
be passed to it, including the names and the types. - ✔✔False; No such list is explicitly
maintained.
✔✔A function in MIPS cannot have loops. - ✔✔False
✔✔In MIPS, the name of a function is a special data type. - ✔✔False
✔✔The jal L1 instruction jumps to L1, and saves the address of L1 into $ra. - ✔✔False.
The next one into $ra