CacheSim/main.cpp

37 lines
1010 B
C++

#include <iostream>
#include <math.h>
#include "simulator.h"
int main(){
std::string temp;
int machineBits, cacheSize, waySize, blockSize;
short setSize;
short offsetSize, tagSize, indexSize;
std::cin >> temp >> temp >> machineBits;
std::cin >> temp >> temp >> cacheSize;
std::cin >> temp >> waySize;
std::cin >> temp >> temp >> blockSize;
setSize = cacheSize * 1024 / blockSize / waySize;
std::cout << setSize << " sets" << std::endl << std::endl;
offsetSize = log2(blockSize);
indexSize = log2(setSize);
tagSize = machineBits - offsetSize - indexSize;
std::cout << "offset: " << offsetSize << std::endl;
std::cout << "index : " << indexSize << std::endl;
std::cout << "tag : " << tagSize << std::endl;
CacheSim::Simulator sim(machineBits, setSize, waySize, tagSize);
std::string action, address;
while(std::cin >> action >> address){
std::cout << "action: "<< action << " address: " << address << std::endl;
sim.read(address);
std::cout << std::endl << std::endl;
}
}