Question

In: Computer Science

Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...

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;
}

Solutions

Expert Solution

#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;
}


Related Solutions

Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
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...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to store a date, which includes day(int), month(int), and year(int). 2.Define a structure to store an address, which includes address(house number and street)(string), city(string), state(string), zip code (string). 3.Define a class to store the following information about a student. It should include private member variables: name(string), ID (int), date of birth (the first structure), address (the second structure), total credit earned (int), and GPA (double)....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT