-
Notifications
You must be signed in to change notification settings - Fork 0
/
reg_file.v
49 lines (40 loc) · 1001 Bytes
/
reg_file.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
`timescale 1ns / 1ps
module reg_file(
input clk,
input RegWrite,
input [ 4:0] read_reg_1,
input [ 4:0] read_reg_2,
input [ 4:0] write_reg,
input [31:0] write_data,
output [31:0] read_data_1,
output [31:0] read_data_2
);
integer i;
reg [31:0] register [0:31];
initial begin
for (i = 0; i < 32; i = i+1)
register[i] = i;
end
assign read_data_1 = register[read_reg_1];
assign read_data_2 = register[read_reg_2];
always @(posedge clk) begin
if (RegWrite == 1'b1) begin
if (write_reg == 5'b0)begin
$display("CAN'T WRITE IN ZERO!");
end
else register[write_reg] = write_data;
$display("hereeee write reg : %d", write_reg);
$display("hereeee2 write data : %d", write_data);
end
end
integer file;
always @(register) begin
file = $fopen("registers.txt","w");
for (i = 0; i < 32; i = i+1)
$fwrite(file,"%d: %b\n",i, register[i]);
$fclose(file);
end
always @(register)begin
$display("reg8 = %d", register[1]);
end
endmodule