-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_memory.v
More file actions
37 lines (26 loc) · 812 Bytes
/
data_memory.v
File metadata and controls
37 lines (26 loc) · 812 Bytes
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
module data_memory (
input wire clk,
input wire WE_dmem,
input wire [15:0] reg_out,
input wire [15:0] alu_out,
output wire [15:0] mem_out
);
// Internal storage for the 65535 memory locations
reg [15:0] memory [0:65535];
// --- INITIALIZATION ---
integer i;
initial begin
for (i = 0; i <= 65535; i = i + 1) begin
memory[i] = 16'h0000;
end
end
//Leave a line to import a premade memory file in the future
// Asynchronous read logic
assign mem_out = memory[alu_out]; // For LW, but active all the time since it's the only possible value for mem_out
// Synchronous write logic
always @(posedge clk) begin
if (WE_dmem) begin // SW
memory[alu_out] <= reg_out;
end
end
endmodule