-
Notifications
You must be signed in to change notification settings - Fork 2
/
dmem.cpp
47 lines (41 loc) · 950 Bytes
/
dmem.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
//dmem.cpp
#include <string>
#include "dmem.h"
/**
* callback of the assynchronous behaviour of module \c dmem
*/
void dmem::read_mem()
{
if(rd.read()) {
//assert(addr.read()<size() && addr.read() % 4 == 0);
if((addr.read()<size() && addr.read() % 4 == 0))
dout.write(memory[addr.read()/4]);
else dout.write(0);
}
}
/**
* callback of the synchronous behaviour of module \c dmem
*/
void dmem::write_mem()
{
if(wr.read()) {
//assert(addr.read()<size() && addr.read() % 4 == 0);
if((addr.read()<size() && addr.read() % 4 == 0)) {
memory[addr.read()/4]=din.read();
//dout.write(memory[addr.read()/4]);
}
}
}
/**
* Writes the contents of memory to \c stdout.
*/
void dmem::dump()
{
unsigned int i;
for(i=0;i<size();i+=4)
printf("%3d: ",i);
printf("\n");
for(i=0;i<size();i+=4)
printf("%5d",(int) memory[i/4]);
printf("\n");
}