-
Notifications
You must be signed in to change notification settings - Fork 2
/
regfile.cpp
55 lines (51 loc) · 1.21 KB
/
regfile.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
#include "regfile.h"
/**
* instantiates the 32 registers %and initializes values to 0.
*/
void regfile::init_regs()
{
memory.clear();
for(int i=0;i<32;i++) memory.push_back(0);
}
/**
* Used for debugging.
*/
void regfile::dump()
{
for(int i=0;i<16;i++) printf(" r%2d",i);
printf("\n");
for(int i=0;i<16;i++) printf("%4d",(int)memory[i]);
printf("\n");
for(int i=0;i<16;i++) printf(" r%2d",i+16);
printf("\n");
for(int i=0;i<16;i++) printf("%4d",(int)memory[i+16]);
printf("\n");
}
/**
* Callback for behaviour of \c regfile module.
*/
void regfile::regfile_access()
{
if(reset.read() == true) {
init_regs();
data1.write(0);
data2.write(0);
s_reg1 = 0;
s_reg2 = 0;
}
else {
if(clk.event() && clk.read()==1 && wr.read()) {
if(regwrite.read() < 32 && regwrite.read() > 0) {
memory[regwrite.read()] = datawr.read();
}
}
if(clk.event() && clk.read()==1 && enable.read() == true) {
if(reg1.read() < 32)
s_reg1 = reg1.read();
if(reg2.read() < 32)
s_reg2 = reg2.read();
}
data1.write(memory[s_reg1.read()]);
data2.write(memory[s_reg2.read()]);
}
}