Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#1 and #3 1. Given the following segment of MIPS Assembly code. Before running t

ID: 3723591 • Letter: #

Question

#1 and #3

1. Given the following segment of MIPS Assembly code. Before running the code. St8-4, $t1-1, $t2-2, and $s0-3 What are the values of St1, St2, and $s0 after running the code? bgez St8, else addi $s0, St8, -5 addi $t1, St1, 2 b next else: move $s0, St8 addi $t2, $12, 3 next: 3. Given the following MIPS Assembly program. What are the values of registers Stl and $t2 after running the program? What is the value at memory location unitX after running the data unitX: word? initA: word-20 30-40 50 0-60 80 ext $t0, initA li Stl, 0 loop: w St2, 0(St0) beqz add addi b $t2, done Stl, St1, $12 Sto, St0, 4 loop done: sw St, unitX(SO)

Explanation / Answer

1)

Before:

$t8=4; $t1=1; $t2=2; $s0=3

bgez $t8,else ; bgez:branch to else if $t8 greater than or equal to zero, true(jump to else)

addi $s0,$t8,-5

addi $t1,$t1,2

b next

else:

move $s0,$t8 ;$s0=$t8=4

addi $t2,$t2,3 ; $t2 = $t2+3 = 2+3 = 5

next:

After:

$t8=4; $t1=1; $t2=5; $s0=4

3)

This code segments calculates sum of the elements in the array and stores this sum into unitX

condition beqz $t2,done ensures that memory locations are iterated till end of the array that is 0 or null which is done usig $t2 and sum is stored in $t1 which is updated in every iteration.

Thus after execution of code $t1=40 & $t2=0. Last instruction sw stores the sum stored in $t1 at memory location unitX thus unitX will also contain 40.