CS计算机代考程序代写 assembler cache /*

/*
CS-UY 2214
Jeff Epstein
Starter code for E20 cache assembler
simcache.cpp
*/

#include
#include
#include
#include
#include
#include #include

using namespace std;

/*
Prints out the correctly-formatted configuration of a cache.

@param cache_name The name of the cache. “L1” or “L2”

@param size The total size of the cache, measured in memory cells.
Excludes metadata

@param assoc The associativity of the cache. One of [1,2,4,8,16]

@param blocksize The blocksize of the cache. One of [1,2,4,8,16,32,64])
*/
void print_cache_config(const string &cache_name, int size, int assoc, int blocksize, int num_lines) {
cout << "Cache " << cache_name << " has size " << size << ", associativity " << assoc << ", blocksize " << blocksize << ", lines " << num_lines << endl; } /* Prints out a correctly-formatted log entry. @param cache_name The name of the cache where the event occurred. "L1" or "L2" @param status The kind of cache event. "SW", "HIT", or "MISS" @param pc The program counter of the memory access instruction @param addr The memory address being accessed. @param line The cache line or set number where the data is stored. */ void print_log_entry(const string &cache_name, const string &status, int pc, int addr, int line) { cout << left << setw(8) << cache_name + " " + status << right << " pc:" << setw(5) << pc << "\taddr:" << setw(5) << addr << "\tline:" << setw(4) << line << endl; } /** Main function Takes command-line args as documented below */ int main(int argc, char *argv[]) { /* Parse the command-line arguments */ char *filename = nullptr; bool do_help = false; bool arg_error = false; string cache_config; for (int i=1; i=argc)
arg_error = true;
else
cache_config = argv[i];
}
else
arg_error = true;
} else {
if (filename == nullptr)
filename = argv[i];
else
arg_error = true;
}
}
/* Display error message if appropriate */
if (arg_error || do_help || filename == nullptr) {
cerr << "usage " << argv[0] << " [-h] [--cache CACHE] filename" << endl << endl; cerr << "Simulate E20 cache" << endl << endl; cerr << "positional arguments:" << endl; cerr << " filename The file containing machine code, typically with .bin suffix" << endl< 0) {
vector parts;
size_t pos;
size_t lastpos = 0;
while ((pos = cache_config.find(“,”, lastpos)) != string::npos) {
parts.push_back(stoi(cache_config.substr(lastpos,pos)));
lastpos = pos + 1;
}
parts.push_back(stoi(cache_config.substr(lastpos)));
if (parts.size() == 3) {
int L1size = parts[0];
int L1assoc = parts[1];
int L1blocksize = parts[2];
// TODO: execute E20 program and simulate one cache here
} else if (parts.size() == 6) {
int L1size = parts[0];
int L1assoc = parts[1];
int L1blocksize = parts[2];
int L2size = parts[3];
int L2assoc = parts[4];
int L2blocksize = parts[5];
// TODO: execute E20 program and simulate two caches here
} else {
cerr << "Invalid cache config" << endl; return 1; } } return 0; } //ra0Eequ6ucie6Jei0koh6phishohm9