-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_memory.v
58 lines (53 loc) · 1.74 KB
/
data_memory.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
module data_memory #(parameter MEM_DEPTH = 16384) (input reset,
input clk,
input [31:0] addr, // address of the data memory
input [31:0] din, // data to be written
input mem_read, // is read signal driven?
input mem_write, // is write signal driven?
output reg [31:0] dout); // output of the data memory at addr
integer i;
// Data memory
reg [31:0] mem[0: MEM_DEPTH - 1];
// Do not touch dmem_addr
wire [13:0] dmem_addr;
assign dmem_addr = addr[15:2]; // 왜 여기도 하필 15:2 인가? 그냥 별 이유 없나?
// Do not touch or use _unused_ok
wire _unused_ok = &{1'b0,
addr[31:16],
addr[1:0],
1'b0};
// TODO
// Asynchrnously read data from the memory
// Synchronously write data to the memory
// (use dmem_addr to access memory)
always@ (*) begin
if(mem_read) begin
dout = mem[dmem_addr];
end
else begin
dout = 0;
end
end
always@ (posedge clk) begin
if(mem_write) begin
mem[dmem_addr] <= din;
end
else begin
i = 0;
end
end
// Initialize data memory (do not touch)
always @(posedge clk) begin
if (reset) begin
for (i = 0; i < MEM_DEPTH; i = i + 1)
// DO NOT TOUCH COMMENT BELOW
/* verilator lint_off BLKSEQ */
mem[i] = 32'b0;
/* verilator lint_on BLKSEQ */
// DO NOT TOUCH COMMENT ABOVE
end
else begin
i = 0;
end
end
endmodule