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; }
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5]...
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5] newVec= [] for i=vec if i>5 new vec=[newvec, i] end end end
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++
Multiples of 2 and 3: write a c++ program Using a while loop, write a program...
Multiples of 2 and 3: write a c++ program Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below.
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
Write assembly code for the following C procedure: i = 1; sum = 0; while (i...
Write assembly code for the following C procedure: i = 1; sum = 0; while (i ≤ n) { sum += i; ++i; } i and sum corresponds to $s1 and $s2. n is preloaded into $s3
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; }
Please code C# Convert the following for loop into a while loop: for(int count = 8;...
Please code C# Convert the following for loop into a while loop: for(int count = 8; count > 0; count--) { Console.WriteLine(count); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT