Solved-Programming Assignment I – Solution

$35.00 $24.00

Instructions Transform the following code into MIPS instructions. Your programs should run correctly on the QtSPIM simulator. Submit your assembly solution (project1.s) containing the neatly written/organized MIPS code in e-Learning (Canvas) website before the deadline. Important You should use comments (‘#’ followed by text) in order to make your programs more readable. The name of…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

Instructions

Transform the following code into MIPS instructions. Your programs should run correctly on the QtSPIM simulator. Submit your assembly solution (project1.s) containing the neatly written/organized MIPS code in e-Learning (Canvas) website before the deadline.

Important

You should use comments (‘#’ followed by text) in order to make your programs more

readable.

The name of the file submitted MUST be “project1.s

You MUST verify that your submission in Canvas is successful by downloading your submission from Canvas and successfully testing it again using SPIM simulator. This will ensure that you uploaded the right file in eLearning and the upload is successful.

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=0;

/*find the average of positive array elements*/ for (i = 0; i < 12; i++) {

if( A[i] > 0 ) {

sum = sum + A[i];

}

}

average = sum/6;

printf(“Average of positive array elements: %d\n”, average);