Question

In: Computer Science

Here is a traditional loop in C:   while (A{i} == 0)                A{i} = A{5} + A{i+3};...

Here is a traditional loop in C:

  while (A{i} == 0)

               A{i} = A{5} + A{i+3};

(NOTE: please consider braces {} here as usual square brackets for array index).

Assume that i is stored in register $s1, and the base address of the array A is in $s2. Fill in the multiple blank spaces in the following MIPS program that is supposed to be compiled from the above C loop:

loop: sll $t0, $s1,

               add $t0, $t0,

               lw $t1, 20($s2)

               lw $t2, ($t0)

               bne $t1, $zero, exit

               j loop

exit:

Solutions

Expert Solution

Answer :-

loop:
           sll $t0, $s1, 2               #creating offset for i

add $t0, $t0, $s2           #creating address of A{i}

lw $t1, 20($s2)               #retrieving value for A{5}

lw $t2, 0($t0)               #retrieving value for A{i}

bne $t2, $zero, exit       #checking A[i]==0 or not
          
           lw $t3, 12{$t0}               #retrieving value for A{i+3}
          
           add $t4, $t1, $t3           #A{5} + A{i+3}
          
           sw $t4, 0($t0)               #A{i} = A{5} + A{i+3}

j loop

exit:


Related Solutions

(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {    ...
(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {     cout<<i<<endl; }
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
write an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
How many times will the following while loop iterate? int i = 1; while (i <...
How many times will the following while loop iterate? int i = 1; while (i < 5) {     i = i + 1;     System.out.println(“Hello!”); } Group of answer choices 4 0 5 It will iterate infinitely
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
All in C++ programming language 1. a.) convert for loop to while loop example b.) convert...
All in C++ programming language 1. a.) convert for loop to while loop example b.) convert while loop to for loop example 2.) pass one dimension array(and its size) to function example
C++ program Reference: while loop, if....else, for loop, the % operator MARTIAN BOOLEAN MULTIPLICATION OBJECTIVE: To...
C++ program Reference: while loop, if....else, for loop, the % operator MARTIAN BOOLEAN MULTIPLICATION OBJECTIVE: To compute the product of two integers using the Martian method of multiplication. INPUT: 5 pairs of positive integers to be multiplied. To be read in one pair at a time. USE A FOR LOOP TO CONTROL THE READING OF THE INPUT OUTPUT: Submit the following: The psuedocode or notes on how you will attack the problem Hand in the complete C++ program, properly commented...
Open Average Test Scores while loop, comment out the while loop and add a for loop...
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C# While loop code using System; class Program { static void Main() { int count = 0, total = 0, number;    while (count < 3) { Console.Write("Enter a number: "); number = Convert.ToInt32(Console.ReadLine()); total += number; count++; }    double average = total / 3.0; Console.Write("Average = " + average.ToString("####0.00")); } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT