Quiz3
Due No due date Points 10
Questions 2 Available until Jan 27 at 4:20pm Time Limit 60 Minutes
Instructions
You can take this quiz only once.
Once you start the quiz, you will need to complete it.
This quiz was locked Jan 27 at 4:20pm.
Attempt History
Attempt Time Score LATEST Attempt 1 10 minutes 10 out of 10
Score for this quiz: 10 out of 10 Submitted Jan 27 at 4:05pm This attempt took 10 minutes.
Question 1
Not yet graded / 3 pts
Write MIPS assembly code that is equivalent to the following code by using beq instead of bne:
bne $s3, $s4, Label1
sub $s0, $s1, $s2 j Label2
Label1: add $s0, $s1, $s2 Label2: ………
Your Answer:
beq $s3 , $s4,Lable1
add $s0,$s1,$s2
j Lable 2
Lable1 : sub $s0,$s1,$s2
lable2: ………….
beq $s3, $s4, Label1 add $s0, $s1, $s2
j Label2
Label1: sub $s0, $s1, $s2 Label2: ……
Question 2
Not yet graded / 7 pts
Write MIPS assembly code for the following C code. Do not use mult, use sll instead. Assume that $s0 contains the value of end, $s1 contains the address of the array numbers, and $s2 contains the values of i.
for (int i = 3; i < end; i++) {
numbers[i] = numbers[i]*16; }
Your Answer:
li $s2, 3 # i = 3
for: bge $s2, $s0, end
sll $t0, $s2, 2
add $t0, $s1, $t0
lw $t1, 0($t0)
sll $t1, $t1, 4
sw $t1, 0($t0)
addi $s2, $s2, 1
j for end:
Quiz Score: 10 out of 10
li $s2, 3 # $s2 = i, i = 3 Loop:
slt $t1, $s2, $s0 # $t1 = 1 if i < end, 0 otherwise
beq $t1, $zero, Exit # if i >= end, # i.e., if $t1=0, then branch to Exit
sll $t2, $s2, 2
add $t3, $s1, $t2 numbers[i]
#
lw sll sw
$t4, 0($t3) $t4, $t4, 4
# temp register $t2 = i*4 # $t3 = address of
= (address of numbers) +(i*4)
# $t4 = numbers[i]
# $t4 = numbers[i]*16
# numbers[i] = $t4 (=
# i = i + 1
# go back to Loop to repeat
$t4, 0($t3) numbers[i]*16)
addi $s2, $s2, 1 j Loop
Exit:
This quiz score has been manually adjusted by +10.0 points.