-
Notifications
You must be signed in to change notification settings - Fork 3
/
RegFile.cpp
53 lines (39 loc) · 998 Bytes
/
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
/*
* @ASCK
*/
#include <systemc.h>
SC_MODULE (RegFile) {
sc_in_clk clk;
sc_in <bool> regWrite;
sc_in <sc_uint<3>> r1;
sc_in <sc_uint<3>> r2;
sc_in <sc_uint<3>> r3;
sc_in <sc_int<8>> data;
sc_out <sc_int<8>> Rr1;
sc_out <sc_int<8>> Rr2;
//testing wires
sc_out <sc_int<8>> r[8];
/*
** module global variables
*/
sc_int<8> reg[8]; // 8 registers in register file
int c = 0;
SC_CTOR (RegFile){
SC_METHOD (process);
sensitive << regWrite << r1 << r2 << r3 << data;
}
void process () {
// whether the regWrite is 0 or not, the Rr1 and Rr2 have the corresponding output!
Rr1.write(reg[r1.read()]);
Rr2.write(reg[r2.read()]);
if(regWrite.read() == 1){
reg[r3.read()] = data.read();
}
for (int i=0; i< 8; i++){
r[i].write(reg[i]);
}
if (c++ == 32) {
reg[0] = 3;
}
}
};