Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In MIPS
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

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

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions