Answered step by step
Verified Expert Solution
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 ;
while i size
j i ;
whilej size
ifArrayi Arrayj
for k j; k size; k Shift elements if element is less than value
Arrayk Arrayk;
size size ; if element deleted, length of array decreases
else
j ;
i ;
Registers Variables
$s Array
$s size
Addresses Contents
$s Array
$s Array
$s Array
$ssize Arrayn
You may use any temporary registers from $t to $t or saved registers from $s to $s Clearly specify your choice of registers and explain your code using comments.
Example Test: If the values of $s through $s and array elements are initialized in the simulator as:
Use the button under the Registers display to initialize register values for $s $s and the button under the Memory display to initialize the initial array elements.
Registers Data
$s
$s
Addresses Contents
The resultant registers are:
Registers Data
$s
$s
The resultant array is:
Addresses Contents
Note: Only the registers $s $s and the first $s elements in memory will be checked by the automated tests.
Grading: automated tests worth points each. manual checks one for comments and one for use of user defined labels worth points each. Manual score will be added after the deadline.
Submission Attempts: You will have limited number of submissions ie only 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started