Example #1
0
int main(int argc, char* argv[]){
	size_t pos = 0;
	int count = 0;

	string input;
	string fOutput;

	//get the input yo
	if(argc > 1){
		input = argv[1];
	} else {
		cerr << "Failed, usage is memTrans <InputFile> \n";
		exit(EXIT_FAILURE);
	}
	
	ifstream fRead(input);
	while(!fRead.eof()){

		getline(fRead,fOutput);
		istringstream r(fOutput);

		unsigned int fOut;
		r >> fOut;

		if(fOut != 0){
		    count++;
			signed int value = getValue(fOut);

			cout << "Virtual address: " << fOut << " ";
			cout << "Physical address: " << getPhysicalAddr(fOut) << " ";
			cout << "Value: " << value << std::endl;
		}
		fOut = 0;
	}

	//close the damn reader
	fRead.close();
	//output needed statistics
	cout << "Number of Translated Addresses = " << count << std::endl;
	cout << "Page faults = " << ptable.getCounter() << std::endl;
	cout << "Page Fault Rate = " << ((double)ptable.getCounter()/(double)count) << std::endl;
	cout << "TLB hits = " << working_tlb.getHits() << std::endl;
	cout << "TLB Hit Rate = = " << ((double)working_tlb.getHits()/(double)count) << std::endl;
	
	//cout << "All Done <(^_^)^" << std::endl;
	return 0;
  }