Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Description: An array of integers can be assigned to a memory address in the .data section of a MIPS assembly language program as show

Assignment Description:

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 three integers, a starting index, an ending index, and an integer to use for a comparison. It should examine only the elements in the array located from the entered starting index, to the entered ending index to check if each of them is greater the last entered integer, then if it is, subtract 3*the last entered integer to each such element in the array. For instance, if a user enters 2, enters 9, then enters 3, then the output will be the following: 45 -6 14 -7 6 -17 2 -4 14 -26 2 19 i.e., the numbers that are located between the index 2 and 9 are examined to see if each of them is greater than the last entered number (3 in this case), then each of such element is subtracted with 3 times that number (3 in this case) if it is. If the entered ending index is larger than 11, then the program should exam elements in the array until the end, and if the entered starting index is less than 0, then it should start examining elements from the first one in the array. 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 12 numbers: .word 45, -6, 23, -7, 15, -17, 11, -4, 23, -26, 2, 19}

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

 int numbers[12] = {45, -6, 23, -7, 15, -17, 11, -4, 23, -26, 2, 19}; int startIndex, endIndex, num1; int j; printf("Enter a starting index: "); //read an integer from a user input and store it in startIndex scanf("%d", &startIndex); printf("Enter an ending index: "); //read an integer from a user input and store it in endIndex scanf("%d", &endIndex); printf("Enter an integer: "); //read an integer from a user input and store it in num1 scanf("%d", &num1); if (startIndex < 0) startIndex = 0; for (j = startIndex; j <= endIndex && j < 12; j = j+1) { if (numbers[j] > num1) { numbers[j] = numbers[j] - (3 * num1); } } printf("Result Array Content: "); for (j = 0; j < 12; j = j+1) { printf("%d ", numbers[j]); } 

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

Enter a starting index: 2 Enter an ending index: 9 Enter an integer: 3 Result Array Content: 45 -6 14 -7 6 -17 2 -4 14 -26 2 19

--------------------------------------------------

The following is another sample output:

--------------------------------------------------

Enter a starting index: -3 Enter an ending index: 12 Enter an integer: 4 Result Array Content: 33 -6 11 -7 3 -17 -1 -4 11 -26 2 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions