-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_memory.v
30 lines (28 loc) · 882 Bytes
/
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
// rising edge sync-write, async-read D-MEM
// height: 64, width: 32 bits (from document "Project Two Specification (V3)")
// address input: 6 bits (64 == 2^6)
// data input/output: 32 bits
// write: on rising edge, when (mem_write == 1)
// read: asynchronous, when (mem_read == 1)
module data_memory (addr, write_data, read_data, clk, reset, mem_read, mem_write);
input [7:0] addr;
input [31:0] write_data;
output [31:0] read_data;
input clk, reset, mem_read, mem_write;
reg [31:0] dmemory [63:0];
integer k;
wire [5:0] shifted_addr;
assign shifted_addr=addr[7:2];
assign read_data = (mem_read) ? dmemory[addr] : 32'bx;
always @(posedge clk or posedge reset)// Ou modifies reset to posedge
begin
if (reset == 1'b1)
begin
for (k=0; k<64; k=k+1) begin
dmemory[k] = 32'b0;
end
end
else
if (mem_write) dmemory[addr] = write_data;
end
endmodule