Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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. A color 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.

HW2-1-shell.c.

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

/* Color Matcher

This program finds the two closest colors in an array of packed RGB values, based on the total component difference (computed as a sum of absolute difference.) It prints the total component difference of the two closest colors.

Date: Your Name: */

#include #include

int main(int argc, char *argv[]) { /* you may change and add to these declarations and initializations */ unsigned Pixels[8]; int NumPixels, MinDelta=-55; // temporary initial value int Load_Mem(char *, unsigned *);

if (argc != 2) { printf("usage: ./HW2-1 valuefile "); exit(1); } NumPixels = Load_Mem(argv[1], Pixels); if (NumPixels != 8) { printf("valuefiles must contain 8 entries "); exit(1); }

/* Your code goes here */ printf("The two closest colors have a total component difference of %d ", MinDelta); exit(0); }

/* This routine loads in up to 8 newline delimited unsigned integers from a named file in the local directory. The values are placed in the passed unsigned integer array. The number of input integers is returned. */

int Load_Mem(char *InputFileName, unsigned PixelArray[]) { int N, Addr, NumVals; unsigned Value; FILE *FP; FP = fopen(InputFileName, "r"); if (FP == NULL) { printf("%s could not be opened; check the filename ", InputFileName); return 0; } else { for (N=0; N < 8; N++) { NumVals = fscanf(FP, "%d: %d", &Addr, &Value); if (NumVals == 2) PixelArray[N] = Value; else break; } fclose(FP); return N; } }

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

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

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

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions