Please help with the following questions. Show all steps. The following MIPS pro
ID: 3875643 • Letter: P
Question
Please help with the following questions. Show all steps.
The following MIPS program computes a function of $9 and $10, and places the result in $11. a) Assume that $9 is initially 5, and $10 is initially 12. What value does $11 have after this program is run? b) Write a mathematical equation that describes this function in terms of $9 and $10. $11- 1. addi $3, $0, 3 add $9, $9, $9 addi $3,$3,1 bne $3, SO, loop add $11, $9, $10 loop: Assume that an add/addi takes one cycle and a bne takes two cycles. How many cycles does it take to execute the program in problem 1? Don't forget that the program loops several times. 2. 3. Implement the following using MiIPs instructions. Do not use any pseudolinstructions for this problem. Branch to a label "stage2" if $tO is greater than or equal to $t1. Implement the following using MIPs instructions. Do not use any pseudoinstructions for this problem If $s1 is less than $s2, set $t5 to 4, otherwise set $t5 to 5 4. 5. Implement the following using MIPs instructions. Do not use any pseudoinstructions for this problem. While $t4 is less than 7, increment St4 by 1 (set St4 to 0 before the loop starts)Explanation / Answer
1. The description of the code is as follows:
addi $3, $0, 3 . it adds 3 to contents of register $0 and stores the result in $3
loop: add $9,$9,$9 . it adds contents of register $9 with $9 and stores result in $9 i.e. it does $9=$9+$9
addi $3,$3,-1 . : it does $3 = $3-1
bne $3,$0,loop. bne stands for branch if not equal. It moves to line pointed by loop if contents of registers $3 and $0 are not equal
add $11,$9,$10 it does $11 = $9 + $10 where $9, $11 , $10 signify the contents of the corresponding registers.
Thus the program is:
$3 = $0 + 3;
while($3 != $0){
$9 = $9 + $9;
$3--;
}
$11 = $9 + $10;
Now $9 is initially 5 and $10 is initially 12
a) The loop runs 3 times. And hence on coming out of the loop, $9 = 40. The $11 = 40 + 12 = 52. Thus contents of $11 is 52.
b) the loop calculates 8 * $9 and outside the loop we do $11 = 8 * $9 + $10. Thus the mathematical relation is $11 = 8 * $9 + $10
2. the first statement runs once and hence takes 1 cycle. The loop runs thrice and each iteration takes 4 cycles. Thus total cycles in the loop is 12. Finally the last statement runs once and takes 1 cycle. Thus the total program takes 1+12+1 = 14 cycles
3.