Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To save some space in Memory, I would like to remove duplicate data, for example duplicate student ID numbers. Towards this, let us consider an

To save some space in Memory, I would like to remove duplicate data, for example duplicate student ID numbers. Towards this, let us consider an array which may contain duplicates. Here we will consider the data to be small integers. The same code can be used for large integer values.
Given an array (base address and number of elements), write a MIPS program to do the following:
delete all duplicate elements.
final array should contain unique integers only.
the size of the array should be updated after deleting duplicates.
Below is an example of the C code segment to perform the above task. You may use a different code, but you have to write the code that you use as a comment before the MIPS code.
// Declaration of variables
int* Array; // Base address of array A
int size; // Length of the array A
int i, j, k; // Given value to be removed from array
// Remove elements equal to val
i =0;
while (i < size){
j = i +1;
while(j < size){
if(Array[i]== Array[j]){
for (k = j; k < size-1; k++){// Shift elements if element is less than value
Array[k]= Array[k+1];
}
size = size -1; // if element deleted, length of array decreases
}
else
j ++;
}
i ++;
}
Registers Variables
$s0 Array
$s1 size
Addresses Contents
$s0 Array[0]
$s0+4 Array[1]
$s0+8 Array[2]
......
$s0+4*(size-1) Array[n-1]
You may use any temporary registers from $t0 to $t9 or saved registers from $s2 to $s7. Clearly specify your choice of registers and explain your code using comments.
Example Test: If the values of $s0 through $s1 and array elements are initialized in the simulator as:
(Use the '+' button under the Registers display to initialize register values for $s0, $s1 and the '+' button under the Memory display to initialize the initial array elements.)
Registers Data
$s04000
$s110
Addresses Contents
40004
40048
4008-13
40128
4016-13
4020-13
40240
40288
40324
40360
The resultant registers are:
Registers Data
$s04000
$s14
The resultant array is:
Addresses Contents
40004
40048
4008-13
40120
Note: Only the registers $s0, $s1 and the first '$s1' elements in memory will be checked by the automated tests.
Grading: 4 automated tests worth 1 points each. 2 manual checks (one for comments and one for use of user defined labels) worth 0.5 points each. Manual score will be added after the deadline.
Submission Attempts: You will have limited number of submissions (5), i.e., only 5 attempts to compare with the automated tests, but you can run the simulator any number of times without clicking on submit for grading.

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

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions

Question

What is paper chromatography?

Answered: 1 week ago

Question

Explain the cost of capital.

Answered: 1 week ago

Question

Define capital structure.

Answered: 1 week ago