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. You are given the following C program that will ask a user to enter one integer and it will filter all integers in the array into the ones that are less than or equals to the entered integer and the ones that are greater. 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. For instance, if a user enters 5, then the output will be the following: -42 3 -6 -18 -27 -28 11 45 12 24 35 14 i.e., the number that are less than 5, (-42, 3, -6, -18, -27, -28) are swapped so that they are located towards the beginning of the array, and the number that are greater than 5, (11, 45, 12, 24, 35, 14) are located towards the end of 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 -42, 11, 24, 3, -6, 14, -18, 45, 12, -27, 35, -28

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

 void main() { int numbers[12] = {-42, 11, 24, 3, -6, 14, -18, 45, 12, -27, 35, -28}; int num1, num2; int i = -1; int j; printf("Enter an integer: "); //read an integer from a user input and store it in num1 scanf("%d", &num1); for (j = 0; j < 12; j = j+1) { if (numbers[j] <= num1) { i = i + 1; num2 = numbers[i]; numbers[i] = numbers[j]; numbers[j] = num2; } } for (j = 0; j < 12; j = j+1) { printf("%d ", numbers[j]); } return; } 

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

Enter an integer: 5 -42 3 -6 -18 -27 -28 11 45 12 24 35 14

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

The following is another sample output:

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

Enter an integer: -20 -42 -27 -28 3 -6 14 -18 45 12 11 35 24

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

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

More Books

Students also viewed these Databases questions

Question

=+ What topics are contained in the contracts?

Answered: 1 week ago

Question

=+Are they specific or general in nature?

Answered: 1 week ago