Starting from:
$35

$29

Homework 2 Solution

The goal of this homework is to explore basic C and MIPS programming skills needed for the project. It also explores File I/O and processing command-line arguments.




HW2-1 In this part, do two tasks:




 
Write a C program that computes the median of a 100 element integer array. The integers in the array will range from -999 to 999. The array may be modified by your program, but the result computed by your program should be the median of the original array. The result should be actual, not a statistical approximation. The result is an integer.




Your program works with a previously defined 100 element vector stored in a file. A shell program is provided to help you get started. The included printf statement should be used to print your result so it can be properly graded. Its output format should not be modified.




 
Modify your program to allow it to accept an additional command-line argument which is the name of an output file. Your program should write the median result to a file of that name using the same print format string used in the printf statement in (1).

While there are many median code examples available (e.g., on the web), you should design, implement, and test your own code. Otherwise you won’t learn the things you need to know for later assignments and exams. Any submitted project containing code not fully created and debugged by the student constitutes academic misconduct.




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 or OS X to develop your program.

Sample value files (test-12.txt, test41.txt, test55.txt, test62.txt, test118.txt) are provided on t-square. You should compile and run your program using the Linux command lines:




 
gcc HW2-1.c –g –Wall –o HW2-1

 
./HW2-1 test215.txt median215.txt




In this example, the input test case is the value file test215.txt and median215.txt is the name of the file to which the program should write the median result.




In order for your solution to be properly received and graded, there are a few requirements.




 
The file must be named HW2-1.c.




 
You name and the date should be included in the header comment.




 
The starting shell program should not be modified except for the replacement of the comment /* your program goes here */ and the addition and/or initialization of declared local variables.




 
Your solution must be properly uploaded to t-square before the scheduled due date, 5:00pm on Wednesday, 8 June. You have a grace period for submission until Wednesday 8 June 2016 at 11:55pm. Your submission will be marked late, but no penalty will be assessed. After 11:55PM, submissions will not be accepted.




HW2-2: In this part, you will write an assembly program Median that computes the median of 100 integers stored in memory. You will call a software interrupt that will store 100 randomly generated numbers in static memory you have reserved. A shell program HW2-2-shell.asm is provided to get you started.







1
ECE 2035 Homework 2










As in part HW2-1, there may be code available from other sources (e.g., on the web, from friends/enemies, etc.); don’t use it! You should figure this out on your own.




Library Routines: There is one library routine (accessible via the swi instruction).




SWI 542: Random: This routine initializes memory beginning at the specified base address

(e.g., Array) with 100 random integers. The integers are in the range -999 to 999. INPUTS: $1




should contain the base address of the 100 words already allocated in memory. OUTPUTS: none.




During testing, from Misasim you can dump the memory array to a text file and run your HW2-1 program on it to see if both your C and ASM programs are getting consistent results. (This is how the value files provided in HW2-1, such as test41.txt, were created.)

In order for your solution to be properly received and graded, there are a few requirements.




 
The file must be named HW2-2.asm.




 
Your name and the date should be included in the beginning of the file.




 
Your program must produce and store the median value in $2 when it returns.




 
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.




 
Your solution must be properly uploaded to t-square before the scheduled due date, 5:00pm on Wednesday, 8 June . You have a grace period for submission until Wednesday 8 June 2016 at 11:55pm. Your submission will be marked late, but no penalty will be assessed. After 11:55PM, submissions will not be accepted.




Project Submission Instructions:




To submit your project, you will upload the answer to each part of the assignment as a separate file.




Double check that the name of the file uploaded is the one you intended to submit.




If you submit a file as the answer to part of the project and later you would like to submit an improved answer, you may submit the more recent version of the file. Only the most recent one will be graded. T-square will not accept submissions after the grace period has ended. In exceptional circumstances, we may accept such late assignments. In those cases, we will open the assignment on t-square for you to submit. All submissions attached to emails will be ignored.





























































2

More products