Question: Translate C code to MIPS assembly language You can create an array in the following way: numbers: .word 0, 0, 0, 0, 0, 0, 0,
Translate C code to MIPS assembly language
You can create an array in the following way:
numbers: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
//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; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
