- Engineering
- Computer Science
- please complete the mipsmisasim code using the completed c code...
Question: please complete the mipsmisasim code using the completed c code...
Question details
Please complete the MIPS/MISASIM Code using the completed C code and the shell code provided.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#HW2-2-shell.asm
# Color Matcher
#
# Your Name:
#
# Date:
#
# This program finds the two closest colors in a eight color
palette.
#
# required output register usage:
# $10: minimum total component difference
# $11 and $12: memory addresses of the two closest colors
.data
Array: .alloc 8 # allocate static space for packed color data
.text
ColorMatch: addi $1, $0, Array # set memory base
swi 500 # create color palette and update memory
######################################################
# Temporary: the following 3 instructions demo use of swi
581.
# Be sure to replace them.
addi $10, $0, 48 # guess min component difference
addi $11, $1, 12 # guess an address
addi $12, $1, 4 # guess an address
######################################################
swi 581 # report answer (in $10, $11, $12)
jr $31 # return to caller
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HW2-1 SOLUTION:
The calculation is essentially:
1.Select first shading from palette
2.Select second shading from palette, from outstanding hues
(we begin from whatever is left of the hues so we don't tally a similar match twice for example [i,j] and [j,i])
3.calculate supreme esteem contrast of the 2 hues
4.if the present contrast is not exactly the base esteem, refresh the base an incentive with the present distinction
The following is the finished code:
/* Color Matcher
This program finds the two nearest hues in a variety of pressed RGB values,
in light of the all out part distinction (processed as a whole of outright
contrast.) It prints the absolute part distinction of the two nearest hues.
Date:
Your Name:
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, roast *argv[]) {
/* you may change and add to these presentations and introductions */
unsigned Pixels[8];
int NumPixels, MinDelta=-55;/impermanent introductory esteem
int Load_Mem(char *, unsigned *);
on the off chance that (argc != 2) {
printf("usage: ./HW2-1 valuefile ");
exit(1);
}
NumPixels = Load_Mem(argv[1], Pixels);
on the off chance that (NumPixels != 8) {
printf("valuefiles must contain 8 passages ");
exit(1);
}
/ - - CODE - - -
int i,j,n=NumPixels;
MinDelta=99999;
/select first shading from palette signified by I
for(i=0;i<n;i++)
{
/select second shading from palette from residual hues
/for example from i+1 to n
for(j=i+1;j<n;j++)
{
int color_diff=(Pixels[i]-Pixels[j]);
/ - - - -
/in the event that we get negative esteem, we convert it to its total esteem
/evacuate this segment if supreme contrast isn't being requested
if(color_diff<0)
color_diff=0-color_diff;
/ - - - -
/checks if the shading distinction of current match is not exactly
/the present least distinction.
if(color_diff<MinDelta)
/refreshes the color_diff
MinDelta=color_diff;
}
}
/ - - - - -
printf("The two nearest hues have a complete segment distinction of %d ", MinDelta);
exit(0);
}
/* This standard loads in up to 8 newline delimited unsigned whole numbers from
a named record in the nearby registry. The qualities are put in the
passed unsigned number exhibit. The quantity of information whole numbers is returned. */
int Load_Mem(char *InputFileName, unsigned PixelArray[]) {
int N, Addr, NumVals;
unsigned Value;
Record *FP;
FP = fopen(InputFileName, "r");
on the off chance that (FP == NULL) {
printf("%s couldn't be opened; check the filename ", InputFileName);
return 0;
} else {
for (N=0; N < 8; N++) {
NumVals = fscanf(FP, "%d: %d", &Addr, &Value);
in the event that (NumVals == 2)
PixelArray[N] = Value;
else
break;
}
fclose(FP);
return N;
}
}
//---------------------------------------------------------------
Solution by an expert tutor
