Question: An array of integers can be assigned to a memory address in the .data section of a MIPS assembly language program as show below. Here
An array of integers can be assigned to a memory address in the .data section of a MIPS assembly language program as show below. Here the length of the array is stored first, and then the elements of the array numbers next. Implement a MIPS assembly language program to perform the functionality of the following C program and print the updated array content, by listing each integer in it. It should ask a user to enter two integers, an integer, and another integer to use for a comparison.
If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it. Name your source code file assignment5.s.
.data numbers_len: .word 10 numbers: .word 23, -7, 15, -17, 11, -4, 23, -26, 27, 8
The following shows how it looks like in a C program:
int numbers_len = 10; int numbers[10] = {23, -7, 15, -17, 11, -4, 23, -26, 27, 8}; int num1, num2, temp; int j; printf("Enter an integer: "); //read an integer from a user input and store it in num1 scanf("%d", &num1); printf("Enter another integer: "); //read an integer from a user input and store it in num2 scanf("%d", &num2); //changing the array content for (j = 0; j < numbers_len; j = j+1) { if (numbers[j] < (num1+num2)) { numbers[j] = numbers[j] + num1 - num2; } } printf("Result Array Content: "); for (j = 0; j < numbers_len; j = j+1) { printf("%d ", numbers[j]); }
The following is a sample output (user input is in bold):
Enter an integer: 15 Enter another integer: -5 Result Array Content: 23 13 15 3 11 16 23 -6 27 28
--------------------------------------------------
The following is another sample output:
--------------------------------------------------
Enter an integer: 12 Enter another integer: 55 Result Array Content: -20 -50 -28 -60 -32 -47 -20 -69 -16 -35
--------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
