-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniProject3.cpp
More file actions
105 lines (80 loc) · 1.89 KB
/
MiniProject3.cpp
File metadata and controls
105 lines (80 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Name: Byron Dowling, Paxton Proctor, Timothy Lockhart
Course: 4103 Operating Systems
Date: 11/12/2021
Assignment: Mini Project #3
*/
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
struct Entry
{
unsigned int Hex_Address;
int command;
int Page_Num;
};
int main()
{
int PT_Size = 12;
unsigned int Hits = 0;
unsigned int Misses = 0;
deque<Entry> TLB;
//deque<Entry>::iterator it;
ifstream Fin;
Fin.open("spice.txt");
//Fin.open("spicy.txt");
while(!Fin.eof())
{
Entry temp;
Fin >> temp.command;
Fin >> hex >> temp.Hex_Address;
temp.Page_Num = (temp.Hex_Address >>12);
if (TLB.size() < PT_Size)
{
if (TLB.empty())
{
TLB.push_back(temp);
Misses++;
}
else
{
bool found = false;
for (int i = 0; i < TLB.size(); i++)
{
if (temp.Page_Num == TLB[i].Page_Num)
{
Hits++;
found = true;
}
}
if (!found)
{
TLB.push_back(temp);
Misses++;
}
}
}
else
{
bool found2 = false;
for (int i = 0; i < TLB.size(); i++)
{
if (temp.Page_Num == TLB[i].Page_Num)
{
found2 = true;
Hits++;
}
}
if (!found2)
{
TLB.pop_front();
TLB.push_back(temp);
Misses++;
}
}
}
cout << "Hits: " << Hits << endl;
cout << "Misses: " << Misses << endl;
return 0;
}