In: Computer Science
Programming Assignment 1 Performance Assessment
Objective:
To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine.
The following is what the program would look like if it were run interactively. Your program will read values without using prompts.
Inputs:
• Clock rate of machine (MHz) • Number of instruction classes (types) • CPI of each type of instruction • Total instruction count for each type of instruction
Specification:
The program calculates the output based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:
1) Enter parameters 2) Print Results 3) Quit
“Print Results” Output Format:
The Print Results option prints out the following information as shown below. Finally use upper case letters and tabs so that your inputs and outputs look just like the example.
FREQUENCY (MHz) input value
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT input value input value input value input value input value input value input value input value input value
PERFORMANCE VALUES
AVERAGE CPI computed value TIME (ms) computed value MIPS computed value
Test Run:
An example of what a test run should look like when run on a terminal on Linux is shown below. All labels should be in CAPS (as shown in the example) and blank lines between input prompts and output lines should be used as in the example.
$ ./aout
(Program Execution Begin)
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 1
Enter the frequency of the machine (MHz): 200
Enter the number of instruction classes: 3
Enter CPI of class 1: 2 Enter instruction count of class 1 (millions): 3
Enter CPI of class 2: 4 Enter instruction count of class 2 (millions): 5
Enter CPI of class 3: 6 Enter instruction count of class 3 (millions): 7
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter Selection: 2
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
Dr. George Lazik (display your full name, not mine)
Performance assessment:
1) Enter Parameters 2) Print Results 3) Quit
Enter selection: 3
Program Terminated Normally
Notes:
Make sure all calculations are displayed truncated to 2 decimal fractional places, using the format “%.2f” in the printf statements.
Be sure that execution time is measured in milliseconds (ms).
To typecast an int x to a float y, use y = (float)x or simply y = 1.0*x
To create proper spacing, use “\t” to tab and “\n” for a new line.
Your Submission to the zyLab:
The source code as a single file named: assignment_1.c, submitted to the zyLab for Assignment 1. It will be graded when you do. You can submit your solution up to 3 times and the best score will be recorded.
You can use any editor and/or compiler you wish, but make sure your code compiles and executes under the gcc compiler on the zyLab; otherwise you will receive 0 points.
Sample Test Bench Run on a zyLab. Note that all input prompts have been eliminated from this version.
The input values:
1 200 3 2 3 4 5 6 7 2 3
The outputs:
Note that spacing is irregular due to publishing quirks here. Use TABS for spacing and you will get correct results.
FREQUENCY (MHz): 200
INSTRUCTION DISTRIBUTION
CLASS CPI COUNT
1 2 3
2 4 5
3 6 7
PERFORMANCE VALUES
AVERAGE CPI 4.53
TIME (ms) 340.00
MIPS 44.12
PROGRAM TERMINATED NORMALLY
Assignment 1 Skeleton
#include <stdio.h>
#include <stdlib.h>
//initialize values
//
int * cpi_i; //define cpi_i as a pointer to one of more
integers
//
// procedure to read all input parameters
//
void enter_params()
{
//initialize counter variables
//
int i;
cpi_sum=0;
instr_total=0;
scanf("%d", &mhz);// input frequency
scanf("%d",&classes);// input number of instruction classes
cpi_i = (int *)malloc(classes*sizeof(int)); //dynamically
allocate an array
count_i = (int *)malloc(classes*sizeof(int));//dynamically allocate
a second array
instr_total =0;
for (i=1; i <= classes; i++)
{
scanf("%d", &cpi_i[i]);// input
instruction's cpi
scanf("%d", &count_i[i]);//
input instruction's count
instr_total += count_i[i];
cpi_sum = cpi_sum + (cpi_i[i] *
count_i[i]);
}
printf("\n");
return;
}
//function computes average cpi
//
float calc_CPI()
{
}
//function computes execution time
//
float calc_CPU_time()
{
}
//function computes mips
//
float calc_MIPS()
{
}
//procedure prints input values that were read
//
void print_params()
{
}
//procedure prints calculated values
//
void print_performance()
{
}
//main program keeps reading menu selection and dispatches
accordingly
//
int main()
{
void fee(cpi_i);//free up space previously allocated above
return 0;
}
#include <stdio.h>
#include <stdlib.h>
//initialize values
//
int * cpi_i; //define cpi_i as a pointer to one of more
integers
int * count_i;
int mhz,classes,instr_total,cpi_sum;
//
// procedure to read all input parameters
//
void enter_params()
{
//initialize counter variables
//
int i;
cpi_sum=0;
instr_total=0;
printf("Enter the frequency of the machine (MHz):");
scanf("%d", &mhz);// input frequency
printf("Enter the number of instruction classes:");
scanf("%d",&classes);// input number of instruction classes
cpi_i = (int *)malloc(classes*sizeof(int)); //dynamically
allocate an array
count_i = (int *)malloc(classes*sizeof(int));//dynamically allocate
a second array
instr_total =0;
for (i=1; i <= classes; i++)
{
printf("Enter CPI of class %d:",i);
scanf("%d", &cpi_i[i]);// input
instruction's cpi
printf("Enter instruction count of class
%d (millions):",i);
scanf("%d", &count_i[i]);//
input instruction's count
instr_total += count_i[i];
cpi_sum = cpi_sum + (cpi_i[i] *
count_i[i]);
}
printf("\n");
return;
}
//function computes average cpi
//
float calc_CPI()
{
return cpi_sum/instr_total;
}
//function computes execution time
//
float calc_CPU_time()
{
return (calc_CPI()*instr_total)/(float)mhz;
}
//function computes mips
//
float calc_MIPS()
{
return (float)mhz/calc_CPI();
}
//procedure prints input values that were read
//
void print_params()
{
printf("FREQUENCY (MHz): %f\n",mhz);
printf("INSTRUCTION DISTRIBUTION\n");
printf("CLASS CPI COUNT\n");
for(int i=1;i<=classes;i++)
{
printf("%d\t%d\t%d\n",i,cpi_i[i],count_i[i]);
}
printf("PERFORMANCE VALUES\n");
printf("AVERAGE CPI\t %.2f", calc_CPI());
printf("TIME (ms)\t %.2f",
calc_CPU_time()*1000);
printf("MIPS\t %.2f", calc_MIPS());
}
//procedure prints calculated values
//
void print_performance()
{
}
//main program keeps reading menu selection and dispatches
accordingly
//
int main()
{
int select;
do{
printf("1) Enter Parameters 2) Print Results 3) Quit
\n");
printf("Enter Selection:");
scanf("%d",&select);
if(select == 1)
{
enter_params();
}
if(select == 2)
{
printf("Performance
assessment:\n");
print_performance();
printf("First_name
Last_name\n");
printf("Performance
assessment:\n");
}
}while(select!=3);
free(cpi_i);//free up space previously allocated
above
free(count_i);
return 0;
}