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

Here I am initializing classes to 0 because when the user enters selection 2 before entering parameters then we will show an error message and return. If you think it's unnecessary put it in comments.

for void fee(cpi_i); So I used free(cpi_i) inside the function where free will free up the memory of cpi_i

I modified enter_params() function as there were instructions for each input. If not required then use your enter_params() function only.

Code:

#include <stdio.h>
#include<stdlib.h>

int *cpi_i;
int *count_i;
int cpi_sum;
int instr_total;
int mhz;
int classes=0;

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()
{

//avg_cpi= cpi_sum/total_instructions
   float avg_cpi=1.0*cpi_sum/instr_total;
   return avg_cpi;
}

//function computes execution time
//
float calc_CPU_time()
{

//CPI*instructions/frequency
   float execution_time=calc_CPI()*instr_total*1000/mhz; //in ms
   return execution_time;
}


//function computes mips
//
float calc_MIPS()
{

//frequency/avg_CPI
   float MIPS=mhz/calc_CPI();
   return MIPS;
}


//procedure prints input values that were read
//
void print_params()
{
   if(classes==0){
       printf("THE PARAMETERS WERE NOT ENTERED, KINDLY SELECT OPTION 1\n");
       return;
   }
   printf("FREQUENCY (MHz):\t%d\n",mhz);
   printf("INSTRUCTION DISTRIBUTION\n");
   printf("CLASS CPI COUNT\n");
   int i;
   for(i=1;i<=classes;++i){
       printf("%d\t%d\t%d\n",i,cpi_i[i],count_i[i]);
   }
}


//procedure prints calculated values
//
void print_performance()
{
   if(classes==0){
       printf("THE PARAMETERS WERE NOT ENTERED, KINDLY SELECT OPTION 1\n");
       return;
   }
   printf("PERFORMANCE VALUES\n");
   printf("AVERAGE CPI\t%.2f\n",calc_CPI());
   printf("TIME (ms)\t%.2f\n",calc_CPU_time());
   printf("MIPS\t%.2f\n",calc_MIPS());
}


//main program keeps reading menu selection and dispatches accordingly
//
int main()
{
   int choice;
   while(1){
       printf("1) Enter Parameters 2) Print Results 3) Quit\n");
       printf("Enter selection: ");
       scanf("%d",&choice);
       if(choice==1){
           enter_params();
       }
       else if(choice==2){
           print_params();
           print_performance();
       }
       else if(choice==3){
           printf("Program Terminated Normally\n");
           break;
       }
       else{
           printf("INVALID CHOICE\n");
       }
   }
  
   void fee(cpi_i);//free up space previously allocated above
   return 0;
}
void fee(cpi_i){
   free(cpi_i);
}

Output:

If you have any doubts or find any errors kindly ask me. Thank you


Related Solutions

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)....
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....
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...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary...
Programming Assignment #2, Processes Write a C program (time_shm.c) that determines the amount of time necessary to run a command from the command line. This program will be run as ./time <command [args...]> and will report the amount of elapsed time to run the specified command. This will involve using fork() and execvp() functions, as well as the gettimeofday() function to determine the elapsed time. It will also require the use of two different IPC mechanisms. The general strategy is...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT