Question
Please complete the following c code: #include #include #include #include cachelab.h // globals int lines_per_set; void printUsage() { printf( Usage: csim [-hv] -s -E -b
Please complete the following c code:
#include
// globals int lines_per_set;
void printUsage() { printf( "Usage: csim [-hv] -s -E
int main( int argc, char * argv[] ) { // using getopt(), parse the command line arguments char * filename= NULL; int option; char verbose= 0; lines_per_set= 0; int s_bits= 0, block_bits= 0, tag_bits= 0; while ( (option= getopt( argc, argv, "hvs:E:b:t:" )) != -1 ) { switch( option ) { case 'h': printUsage(); exit(EXIT_SUCCESS); break; case 'v': verbose= 1; break; case 's': s_bits= atoi( optarg ); break; case 'E': lines_per_set= atoi( optarg ); break; case 'b': block_bits= atoi( optarg ); break; case 't': filename= optarg; break; default: printf( "Unknown option encountered " ); printUsage(); exit(EXIT_FAILURE); } } if ( s_bits == 0 || lines_per_set == 0 || block_bits == 0 ) { printf( "Value for cache parameter not passed on command line " ); printUsage(); exit(EXIT_FAILURE); } // compute the number of tag bits // allocate the cache // zero out the cache // initialize the time variable // open the trace file int hit_total= 0, miss_total= 0, eviction_total= 0; // read each line in the trace file // if the line represents an instruction // skip over it // compute the set and tag bits // if the data exists in the cache // increment counter(s) and update the entry time // else // get the next free line in the set // if no free line exists, evict a line using the LRU algorithm // place the data in the cache and set the entry time // increment counter(s) // close the file // free the cache printSummary( hit_total, miss_total, eviction_total ); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started