Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #include "cachelab.h"

// globals int lines_per_set;

void printUsage() { printf( "Usage: csim [-hv] -s -E -b -t " ); }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

ISBN: 978-0764535376

More Books

Students also viewed these Databases questions