Question: Transform the following code into MIPS instructions. Your programs should run correctly on the QtSPIM simulator. Problem Statement We have an array A which has
Transform the following code into MIPS instructions. Your programs should run correctly on the QtSPIM simulator.
Problem Statement We have an array A which has 12 numbers out of which 6 are positive and other 6, negative. All numbers are unique integer numbers (no duplicates). The allowed numbers are in the range -100 to 100 (0 is excluded). Calculate the average of only the positive elements and print the result. Your assembly implementation should exactly follow the pseudo code sequence given below. Please do not perform any optimization at pseudo code level or at assembly level. Inputs: A[12] = {-89, 19, 91, -23, -31, -96, 3, 67, 17, 13, -43, -74} We will also test your code using other possible values in the A array. The array A will always have 12 unique integer numbers in the range -100 to 100 (0 is excluded) out of which 6 are positive. Sum of positive numbers will always be divisible by the number of positive numbers. Please test your MIPS assembly with other possible values in A.
Outputs (with expected values for the above input) Average of positive array elements: 35
Tips: For printing to/reading from console, you should first load correct value to register $v0, and then call syscall method. If there is an input, the value would be returned in $v0. There is no need to get inputs from the console. Array A can be hard coded in the source file. We will change it to test your code with different inputs.
Pseudo -code: int A[12] = {-89, 19, 91, -23, -31, -96, 3, 67, 17, 13, -43, -74); int sum = 0; int average 0; int i-o; /*find the average of positive array elements*/ for (i = 0; i 12; i++) { if( A[i] 0 ) { sum sum A[i]; averagesum/6; printf("Average of positive array elements: %d ", average)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
