-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregfile.v
174 lines (153 loc) · 3.9 KB
/
regfile.v
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//TEST BENCH
module testbench();
reg clk,ctrl,reset;
wire [7:0] OUT1,OUT2;
reg [7:0] IN;
reg [2:0] INaddr,OUT1addr,OUT2addr;
// Initialize all variables
initial begin
$display ("time\t clk reset ctrl in out1 out2");
$monitor ("%g\t %d %d %d %d %d %d", $time, clk, reset, ctrl, IN, OUT1, OUT2);
clk = 0; // initial value of clock
reset = 0; // initial value of reset
ctrl = 1;
//write
#5 ctrl = 0;
#5 @(negedge clk) INaddr = 2;
#5 @(negedge clk) IN = 200;
#5 @(negedge clk) INaddr = 4;
#5 @(negedge clk) IN = 100;
$dumpfile("R.vcd");
$dumpvars(0, regF);
//read
#5 ctrl=1;
#5 @(posedge clk) OUT1addr = 2;
#5 @(posedge clk) OUT2addr = 4;
//reset
#5 reset=1;
#5 @(posedge clk) OUT1addr = 2;
#5 @(posedge clk) OUT2addr = 4;
// off reset
#5 reset=0;
//write
#5 ctrl=0;
#5 @(negedge clk) INaddr = 2;
#5 @(negedge clk) IN = 33;
//read
#5 ctrl=1;
#5 @(posedge clk) OUT1addr = 2;
#5 @(posedge clk) OUT2addr = 4;
#5 $finish; // Terminate simulation
end
// Clock generator
always begin
#5 clk = ~clk; // Toggle clock every 5 ticks
end
//connect reg-file with testbench
regfile8x8a regF(IN, OUT1, OUT2, INaddr, OUT1addr, OUT2addr, clk, reset, ctrl);
endmodule
//REGISTER FILE
module regfile8x8a(CLK, INaddr, IN, OUT1addr, OUT1, OUT2addr, OUT2, busy_wait);
input [7:0] IN;
output reg [7:0] OUT1;
output reg [7:0] OUT2;
input [2:0] INaddr;
input [2:0] OUT1addr;
input [2:0] OUT2addr;
input CLK;
input busy_wait;
reg [7:0] register0, register1, register2, register3, register4, register5, register6, register7;
// Write functionality
always @(negedge CLK ) begin
if (!busy_wait) begin
case (INaddr)
0: begin
register0 <= IN;
end
1: begin
register1 <= IN;
end
2: begin
register2 <= IN;
end
3: begin
register3 <= IN;
end
4: begin
register4 <= IN;
end
5: begin
register5 <= IN;
end
6: begin
register6 <= IN;
end
7: begin
register7 <= IN;
end
endcase // case (wrAddr)
end
end
// always @ (posedge clk)
// Read functionality
always @(posedge CLK ) begin
//OUT1
case (OUT1addr)
0: begin
OUT1 <= register0;
end
1: begin
OUT1 <= register1;
end
2: begin
OUT1 <= register2;
end
3: begin
OUT1 <= register3;
end
4: begin
OUT1 <= register4;
end
5: begin
OUT1 <= register5;
end
6: begin
OUT1 <= register6;
end
7: begin
OUT1 <= register7;
end
default:
OUT1 <= 0;
endcase
//OUT2
case (OUT2addr)
0: begin
OUT2 <= register0;
end
1: begin
OUT2 <= register1;
end
2: begin
OUT2 <= register2;
end
3: begin
OUT2 <= register3;
end
4: begin
OUT2 <= register4;
end
5: begin
OUT2 <= register5;
end
6: begin
OUT2 <= register6;
end
7: begin
OUT2 <= register7;
end
default:
OUT2 <= 0;
endcase
end
endmodule