-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregfile.v
81 lines (72 loc) · 1.75 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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 14:35:52 12/04/2015
// Design Name:
// Module Name: regfile
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module regfile(
input clk,
input rst,
input we,
input wire[4:0] waddr,
input wire[31:0] wdata,
input re1,
input wire[4:0] raddr1,
output reg[31:0] rdata1,
input re2,
input wire[4:0] raddr2,
output reg[31:0] rdata2
);
/* Define 32 x 32 regs */
reg[31:0] regs[0:31];
/* Reset */
integer i;
/* Wirte to waddr */
always @ (posedge clk) begin
if(rst == 0 && we == 1 && waddr != 0)
regs[waddr] <= wdata;
else if (rst == 1)
for(i = 0; i < 32; i = i + 1)
regs[i] <= wdata;
end
/* Read from raddr1 */
always @ (*) begin
if(rst == 1)
rdata1 <= 0;
else if (raddr1 == 0)
rdata1 <= 0;
else if (raddr1 == waddr && we == 1 && re1 == 1)
rdata1 <= wdata;
else if (re1 == 1)
rdata1 <= regs[raddr1];
else
rdata1 <= 0;
end
/* Read from raddr2 */
always @ (*) begin
if(rst == 1)
rdata2 <= 0;
else if (raddr2 == 0)
rdata2 <= 0;
else if (raddr2 == waddr && we == 1 && re1 == 1)
rdata2 <= wdata;
else if (re2 == 1)
rdata2 <= regs[raddr2];
else
rdata2 <= 0;
end
endmodule