Project 2
CS 345
Computer Organization
15 Points
Due Wednesday, Mar. 11, 2015 at 11:59:59 pm


MPG Problem

Write a program in a high level language (that is, in C) to compute miles per gallon (mpg) given the number of miles travelled and the number of gallons used on a trip.  This program must be capable of continuously reading the number of miles travelled and the number of gallons to produce corresponding output for the resulting mpg.  You may assume that the user may stop the program at any time by entering a sentinel value of zero for the number of gallons used on a trip.  Note that you must account for the fact that no negative values should be provided as input.  This program must also compute the average mpg for all input data.

Within this program you must make use of two functions. The first function must take as a parameter the number of miles travelled and the number of gallons used.   It must return the the miles per gallon for that trip.  The second function must take as a parameter the number of trips and the sum of the miles per gallon for all trips.   This second function must return the average miles per gallon for all input data.

Provided below is a list of inputs, outputs, and sentinel values.

Inputs: miles travelled and gallons used

Outputs: miles per gallon for every input pair, average miles per gallon over all input

Once you have completed the high level language program, convert your program to assembly.

Testing

Develop and write out test cases for your program.  Be sure to test your program thoroughly including any boundary conditions.

Sample Input/Output Examples

Enter the miles and gallons on one line each, respectively.
230
9.4
For 230.0 mi and 9.4 gal, the resulting mpg is 24.46808510638298
Enter the miles and gallons on one line each, respectively.
451
15.2
For 451.0 mi and 15.2 gal, the resulting mpg is 29.67105263157895
Enter the miles and gallons on one line each, respectively.
429
15.5
For 429.0 mi and 15.5 gal, the resulting mpg is 27.677419354838708
Enter the miles and gallons on one line each, respectively.
0
0
The average mpg is 27.68079800498753

Additional Example Input/Output

Enter the miles and gallons on one line each, respectively.
132
3.2
For 132.0 mi and 3.2 gal, the resulting mpg is 41.25
Enter the miles and gallons on one line each, respectively.
88
23.3
For 88.0 mi and 23.3 gal, the resulting mpg is 3.776824034334764
Enter the miles and gallons on one line each, respectively.
-2
22
Invalid entry.
Enter the miles and gallons on one line each, respectively.
22
-0.1
Invalid entry.
Enter the miles and gallons on one line each, respectively.
-1
-1
Invalid entry.
Enter the miles and gallons on one line each, respectively.
334
8.4
For 334.0 mi and 8.4 gal, the resulting mpg is 39.76190476190476
Enter the miles and gallons on one line each, respectively.
0
-23
The average mpg is 15.873925501432666

Hints

You will need to use double precision floating point operations to complete this assignment with MIPS.  These include double addition add.d, the double absolute value function abs.d, double division div.d,  the double comparison instruction c.lt.d, the instruction to move a double value from one register to another mov.d, load double l.d, load single l.s,  and converting an integer to a double cvt.d.w.  You will also need to make use of MIPS integer comparison and branching functionality such as the sle, b and bc1f instructions.

Submission

Submit your C source code, MIPS assembly code, and list of test cases to the eCompanion Dropbox for Project 2.