Name: MIPS Programming Assignment 6 (Analyzing MIPS Assembly Code) 1. Given the
ID: 3723451 • Letter: N
Question
Name: MIPS Programming Assignment 6 (Analyzing MIPS Assembly Code) 1. Given the following segment of MIPS2. Given the following segment of MIPS Assembly code. Before running the code. Sts-4, St 1=1, St2-2, and Sso-3. What are the values of St1, S12, and Ss0 after running the code? Assembly code. Before running the code, Sal 1 and Sa2-7 What are the values of Sal and Sa2 after running the code? while: bge Sal, Sa2, done bgez St8, else addi Ss0, $t8,-5 addi St1, St1, 2 b next addi Sal, Sal, 1 addi Sa2, Sa2,-1 b while else: move Ss0, St8 done: addi $t2, S12, 3 next: 3. Given the following MIPS Assembly program. What are the values of registers Stl and St2 after running the program? What is the value at memory location unitX after running the program? 4. Given the following MIPS Assembly program. What are the values of registers $13 and St4 after running the program? What is the value at memory location unitX after running the program? word 28 num: initA: word-20 30-40 50 0-60 80 unitX: word? initA: word-20 30-40 500-60 80 unitX: word? .text la St0, initA lw Stl, num(S0) add $12, StO, St li St3, 0 addi $12, $t2, -4 .text la StO, initA li Stl, 0 loop: lw S12,0(St0) beqz $12, done add St1, St1, S12 addi $t0, St0, 4 b loop loop: blt S12, StO, done lw St4, 0($12) add $t3, S13, $t4 addi $t2, $12,-4 b loop done: sw St1, unitX(S0) done: sw St3, unitX(SO)Explanation / Answer
1. Before running code:
$t8 = 4
$t1 = 1
$t2 = 2
$s0 = 3
bgez $t8, else // branch to else if $t8>= 0. $t8 is greater than 0 therefore branch to else
addi $s0 , $t8 , -5 // $s0 = $t8 + (-5)
addi $t1,$t1,2 // $t1 = $t1 + 2
b next //branch tro next
else: move $s0, $t8 // move $t8 to $s0
addi $t2 , $t2 ,3 // $t2 = $t2 + 3
next:
1st statement i.e. bgez $t8, else branches code to else as $t8>=0
Then, statements
else: move $s0, $t8
addi $t2 , $t2 ,3
are executed.
i.e. $s0 = $t8
$s0 = 4
$t2 = $t2 +3 = 2+3
$t2 = 5
Values of $t1 = 1(remains same) , $t2 = 5 , $s0 = 4
2. $a1 = 1 and $a2 = 7 before running code
while: bge $a1,$a2,done // branch to done if a1>=a2
addi $a1 , $a1 ,1 //$a1 = $a1 + 1
addi $a2 , $a2 , -1 //$a2 = $a2 -1
b while // branch to while
done:
In the first run , $a1 = 1 and $a7 = 7
$a1 < $a2 so next instruction addi $a1 , $a1,1 and addi $a2, $a2 , -1 is executed
So, $a1 becomes 2 and $a2 = 6
Code branch back to while
In second run, $a1 <$a2
So, again $a1 = $a1 +1 = 3
$a2 = $a2 -1 = 5
Code branch back to while
In 3rd run
$a1 <$a2
So, $a1 = $a1 +1 = 4
$a2 = $a2 - 1 = 4
Code branch back to while
In 4th run,
$a1 == $a2 so code branches to done
Values of $a1 =4 and $a2 = 4 after running code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.