Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been attempting this numerous times please help: Assignment Description: Implement a MIPS assembly language program that defines main, readArray, printArray, and modifyArray procedures/functions.

I have been attempting this numerous times please help:

Assignment Description:

Implement a MIPS assembly language program that defines main, readArray, printArray, and modifyArray procedures/functions. The readArray takes an array of integers as its parameter, asks a user how many numbers will be entered, then reads in integers from a user to fill the array. The printArray takes an array of integers as its parameter, prints each integer of the array. The modifyArray procedure/function takes parameters of arrays of integers, and also asks a user to enter two integers, and decide which one is larger and which one is smaller. Then it goes through each element of the array, and if it is larger than the maximum of two integers, it subtracts the maximum value from it, and if it is smaller than the minimum of two integers, it adds the minimum value to it. The main procedure/function asks a user to enter how many times the operation should be repeated, then it calls readArray function to populate the array, calls printArray to print out its original content, calls modifyArray to change it content, then calls printArray again to print out its result content. Please see the following C program to understand how it should work.

You can create an array in the following way:

numbers: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

The following shows how it looks like in a C program:

 //The readArray function reads integers from user input and store them in the array int readArray(int array[], int size) { int num, i = 0; int length; printf("Specify how many numbers should be stored in the array (at most 10): "); scanf("%d", &length); while (i < size && i < length) { printf("Enter an integer: "); //read an integer from a user input and store it in num1 scanf("%d", &num); array[i] = num; i++; } return length; } //The printArray function prints integers of the array void printArray(int array[], int size, int length) { int i; printf(" Array Content: "); i = 0; while (i < size && i < length) { printf("%d ", array[i]); i++; } return; } //The modifyArray reads in two integers. //Then it goes through the parameter array, and if an element //is larger than the maximum of two integers, then subtracts the maximum value from it //and if an element is smaller than the minumum of two integers, //then it adds the minimum value to it. void modifyArray(int array1[], int size, int length) { int i; int num1, num2, min, max; printf("Enter an integer: "); //read an integer from a user input scanf("%d", &num1); printf("Enter another integer: "); //read an integer from a user input scanf("%d", &num2); //deciding which one is larger and which one is smaller if (num1 > num2) { max = num1; min = num2; } else { max = num2; min = num1; } //It goes through each element of array //and change their values if the conditions are met i = 0; while (i < size && i < length) { if (array1[i] > max) array1[i] = array1[i] - max; else if (array1[i] < min) array1[i] = array1[i] + min; i++; } return; } //The main asks a user how many time to repeat //the operation. Then it reads in an array content, //prints it, changes it contents, then prints its result contant. void main() { int arraysize = 10, length; int numbers[arraysize]; int howMany; int i; printf("Specify how many times to repeat: "); scanf("%d", &howMany); i=0; while (i < howMany) { length = readArray(numbers, arraysize); printArray(numbers, arraysize, length); modifyArray(numbers, arraysize, length); printArray(numbers, arraysize, length); i++; } return; } 

The following is a sample output (user input is in bold):

Specify how many times to repeat: 2 Specify how many numbers should be stored in the array (at most 10): 9 Enter an integer: 1 Enter an integer: -12 Enter an integer: 53 Enter an integer: -4 Enter an integer: 5 Enter an integer: 32 Enter an integer: 1 Enter an integer: 7 Enter an integer: -5 Array Content: 1 -12 53 -4 5 32 1 7 -5 Enter an integer: 7 Enter another integer: -3 Array Content: 1 -15 46 -7 5 25 1 7 -8 Specify how many numbers should be stored in the array (at most 10): 8 Enter an integer: 1 Enter an integer: -12 Enter an integer: 53 Enter an integer: -4 Enter an integer: 5 Enter an integer: 32 Enter an integer: 1 Enter an integer: 7 Array Content: 1 -12 53 -4 5 32 1 7 Enter an integer: 6 Enter another integer: -3 Array Content: 1 -15 47 -7 5 26 1 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions