-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataMemory.cpp
69 lines (64 loc) · 2.62 KB
/
DataMemory.cpp
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
#include "DataMemory.h"
#include "stdHeader.h"
//////////////////////////////////////////////////////////
//DataMemory constructor
//sets the value of data memory to that of a map with unsigned 32 bit integers
//////////////////////////////////////////////////////////
DataMemory::DataMemory(std::map<u32, u32> data_m)
{
data = data_m;
}
//////////////////////////////////////////////////////////
//DataMemory destructor
//////////////////////////////////////////////////////////
DataMemory::~DataMemory() {}
//////////////////////////////////////////////////////////
//DataMemory empty constructor
//////////////////////////////////////////////////////////
DataMemory::DataMemory() {}
//////////////////////////////////////////////////////////
//DataMemory print methods
//////////////////////////////////////////////////////////
void DataMemory::print_out()
{
std::cout << " ------------- " << std::endl;
std::cout << "| Data Memory |" << std::endl;
std::cout << " ------------- " << std::endl;
std::cout << "Address: 0x" << std::hex << address << std::endl;
std::cout << "Read Data: 0x" << std::hex << read_data << std::endl;
printf("Write Data: 0x%08x\n", write_data);
std::cout << "Control Line - MemRead: 0x" << std::hex << control_read << std::endl;
std::cout << "Control Line - MemWrite: 0x" << std::hex << control_write << std::endl;
std::cout << "Memory Contents..." << std::endl;
//////////////////////////////////////////////////////////
//iterates through the map and prints the hex values at each specific indice
//////////////////////////////////////////////////////////
for(auto iter = data.begin(); iter != data.end(); ++iter)
{
std::cout << "0x" << std::hex << iter->first << ":" << iter->second << std::endl;
}
std::cout << std::endl;
}
//////////////////////////////////////////////////////////
//execute method for data memory and depending on the values of the control code will perform a read or write
//////////////////////////////////////////////////////////
void DataMemory::execute()
{
if(control_read == 1)
{
//////////////////////////////////////////////////////////
//this is a data read
//retrieve data at this->address
//set it to this->read_data
//////////////////////////////////////////////////////////
read_data = data[address];
}
else if(control_write == 1)
{
//////////////////////////////////////////////////////////
//this is a data write
//write the data at this->address with this->write_data
//////////////////////////////////////////////////////////
data[address] = write_data;
}
}