1. Engineering
  2. Computer Science
  3. 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.

Summary: Many computer vision applications require the comparison of the color of image pixels, for example, in tracking based on object appearance. This assignment explores the function and implementation of several basic conditional execution, nested iteration, and memory access mechanisms to realize a color matching program. RGB representation and selects the two that most closely match (as measured in total component difference). The total difference of the closest colors is also determined. The program compares eight colors stored in memory in a packed Background: Digital imaging devices often represent color pixel data as a triple of typically eight bit integers representing the intensity of its red, green, and blue components (RGB foa). Since most of todays computers employ 32-bit words, the color of a single pixel is encoded in a packed representation, shown below. 31 unused red component n component blue component 31 24 23 16 15 In this assignment, eight such values are created and stored in memory. There are several commonly used metrics to assess color difference. In this case, color differences are measured as the total component difference, also known as the sum of absolute difference (SAD), defined as: ColorDifferencA-A,-B A,-B where the subscript indicates the red (r), green (g), or blue (b) component of color A or B. To compute the minimum color difference, all combinations of different colors must be compared. . Color Match 1.0 (58.86, 167) く22, 170. 25) (239, 171, 138) (25, 51, 27) 187, 39, 73) [S8, 150. 206) [38, 159, 72) 《247, 24, 233) 5012 5016 5020 5024 5028 5032 5036 5040 Figure 1: Color Palette generated by swi 500, with (R, G, B) values listed above, memory addresses below. Objective: For this assignment, you will write two programs, one in C and one in MIPS. There are three key tasks each color matching program needs to be able to do: 1. Unpack a color by pulling the individual unsigned 8-bit red, green, and blue component values from the lower 24 bits of a 32-bit integer. Hint: in C, the shift (<<, >>) and mask (&) operators may be useful; in MIPS, the load byte instructions may be helpful //www.ece.gatech.edu/academic/courses/ece2035/assi oad-Store- Note that the Misasim memory at the word address is little endian: the least significant byte is locatedObjective: For this assignment, you will write two programs, one in C and one in MIPS. There are three key tasks each color matching program needs to be able to do: 1. Unpack a color by pulling the individual unsigned 8-bit red, green, and blue component values from the lower 24 bits of a 32-bit integer. Hint: in C, the shift (<<, >>) and mask (&) operators may be useful; in MIPS, the load byte instructions may be helpful (http://www.ece.gatech edu/academic/courses/ece2035/assignments/Load-Store-Byte-Insts.pdf Note that the Misasim memory implementation is little endian: the least significant byte is located at the word address. 2. Compute the color difference (SAD) between two given unpacked colors using the formula given above. 3. Use nested loops and conditionals to orchestrate the comparison of all pairs of unpacked colors to find the pair with the minimum SAD.Project Deliverables 1. Design and implement a C version of the color match program. As a starting point, use the file Hw2-1-shell.c. The program should employ a reasonable algorithm that compares all pairings of colors in the palette exactly once. Acolor should not be compared to itself. Nor should two colors be compared to each other more than once. Your C program should print out the total component color difference for the closest pair using the print string provided in the shell code Name the file HW2-1.C and upload it to Canvas by the scheduled due date. The shell program HW2-1-shell.c includes a reader function Load_Mem() that loads the values from a text file. You should use gcc under Ubuntu to develop your program. Sample test files (test119.txt, test30.txt, test111.txt) are provided - the number in the name of each file indicates the correct answer for the min component difference. You should compile and run your program using the Linux command lines: >gcc HW2-1.c -g -Wall -o HW2-1 /HW2-1 test119.txt You can create additional test files using MiSaSiM to run HW2-2-shell.asm, go to the end of the trace, and use the Dump memory menu button to save the memory to a text file with the correct answer (the value in $13) in the name of the file. 2. Design and implement a MIPS version of the color match program. A description of the MIPS library routines you need is given below. Use the file HW2-2-shell.asm as a starting point. The results should be returned by your program in $10 (minimum total component difference), $11 (memory address of closest color A), and $12 (memory address of closest color B). You must use these register conventions or the automated grader will score your program incorrectly Memory should only be used for input to your program. Your program must return to the operating system via the jr instruction Programs that include infinite loops or produce simulator warnings or errors will receive zero credit. Name the file HW2-2.asm and upload it to Canvas by the scheduled due date.MIPS Library Routine: There are two library routines (accessible via the swi instruction). SwI 500: Create Palette: This routine generates and displays eight random colors as shown in the example in Figure 1. It initializes memory with the 8 packed colors beginning at the specified base address (eg, Array). INEUTS: $1 should contain the base address of the 8 words (32 bytes) already allocated in memory. OUTPUTS: the 8 words allocated in memory contain the 8 packed RGB color values to be used as input data. Hint: To more easily view the RGB color components in the memory, you can select hexadecimal for the display base in MiSaSiMs menu button Options (the wrench). For example, for a color whose RGB value is (60, 5, 13), the packed value is 0x3 c0500 SWI581: Report Closest Colors: This routine allows you to report your answer and an oracle provides the correct answer so that you can validate your code during testing. INPUTS: $10 should contain the minimum total component difference you computed across all pairs of colors, S11 and $12 should contain the memory addresses of the two closest colors (and may be provided in either order). OUTPUTS: $13 gives the correct minimum total component difference, $14 and $15 will contain the cor- rect memory addresses of the two closest colors. If you cll sui 5981 more than once in your code, onmly the first ansiwer that you provide will be recorded.

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

#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
Blurred Solution
This question has been solved
Subscribe to see this solution