ASU Implement a Mips Assembly Language Program Project Paper
Objectives:-write assembly language programs to: -define procedures/functions and call them. -create loops -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard.Assignment Description:Implement a MIPS assembly language program that defines main, readArray, printArray, and exchangeElements procedures/functions.The readArray takes an array of integers as its parameter, 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 exchangeElements procedure/function takes parameters of two arrays of integers, asks a user to specify how many integers to read, then calls the readArray function twice for each of two arrays, then exchanges two elements from two arrays when the index is even. (Please see the C program below), then print out the result contents for the two arrays. It also returns how many numbers are exchanged.The main procedure/function calls exchangeElements function and print out the number of elements exchanged. Please see the following C program to understand how it should work.If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it. Name your source code file assignment6.s.You can create an array in the following way:numbers1: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0numbers2: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0The following shows how it looks like in a C program: //The readArray procedure reads integers from user input and store them in the array void readArray(int array[], int length, int howMany, int number) { int num, i = 0; while (i < howMany && i < length) { printf("Enter an integer: \n"); //read an integer from a user input and store it in num1 scanf("%d", &num); array[i] = num; i++; } printf("\nThe array %d content:\n", number); i = 0; while (i < howMany && i < length) { printf("%d\n", array[i]); i++; } return; } //The printArray procedure prints integers of the array void printArray(int array[], int length, int howMany, int number) { int i; printf("\nResult array %d Content:\n", number); i = 0; while (i < howMany && i < length) { printf("%d\n", array[i]); i++; } return; } //The exchangeElements calls readArray procedure to populate two arrays, //then exchange elements from two arrays at even indexes, then print the result arrays. int exchangeElements(int array1[], int array2[], int length) { int i, temp; int howMany, count; printf("Specify how many numbers should be stored in the arrays (at most 11):\n"); scanf("%d", &howMany); readArray(array1, length, howMany, 1); readArray(array2, length, howMany, 2); i = 0; count = 0; //exchange two elements from two arrays at even indexes while (i < howMany && i < length) { if (i%2 == 0) { temp = array1[i]; array1[i] = array2[i]; array2[i] = temp; count++; } i++; } printArray(array1, length, howMany, 1); printArray(array2, length, howMany, 2); return count; } // The main calls the exchangeElements void main() { int arraysize = 11; int numbers1[arraysize], numbers2[arraysize]; int number = exchangeElements(numbers1, numbers2, arraysize); //print out how many elements are exchanged printf("%d element(s) exchanged\n", number); return; } The following is a sample output (user input is in bold):Specify how many numbers should be stored in the arrays (at most 11):8Enter an integer:1Enter an integer:-12Enter an integer:53Enter an integer:-4Enter an integer:5Enter an integer:32Enter an integer:1Enter an integer:7The array 1 content:1-1253-453217Enter an integer:1Enter an integer:7Enter an integer:1Enter an integer:5Enter an integer:1Enter an integer:-5Enter an integer:-2Enter an integer:3The array 2 content:17151-5-23Result array 1 Content:1-121-4132-27Result array 2 Content:175355-5134 element(s) exchanged--------------------------------------------------Each procedure/function needs to have a header using the following format:############################################################################# Procedure/Function readArray# Description: -----# parameters: $a0 = address of array1 , $a1 = addres of array2, $a3 = length# return value: $v1 = count# registers to be used: $s3 and $s4 will be used.############################################################################