-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMem.cpp
More file actions
39 lines (33 loc) · 941 Bytes
/
DMem.cpp
File metadata and controls
39 lines (33 loc) · 941 Bytes
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
#include "DMem.h"
void DMem::write_data(int address, int value) {
if (!ctr.getMemWrite()) {
return;
}
// Insert those value to address
map<int, int>::iterator tmp_finder = data_memory.find(address);
if (tmp_finder != data_memory.end()) {
tmp_finder->second = value;
cout << "Overwrited" << endl;
} else {
data_memory.insert(make_pair(address, value));
}
}
int DMem::read_data(int address) {
if (!ctr.getMemRead()) {
return -1;
}
map<int, int>::iterator tmp_finder = data_memory.find(address);
if (tmp_finder != data_memory.end()) {
return tmp_finder->second;
} else {
return -1;
}
}
void DMem::print_all() {
for(auto it = data_memory.cbegin(); it != data_memory.cend(); ++it) {
cout << "Address: " << it->first << " Values: " << it->second << endl;
}
}
void DMem::set_control(Control& c) {
this->ctr = c;
}