-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataMemory.v
More file actions
40 lines (35 loc) · 962 Bytes
/
DataMemory.v
File metadata and controls
40 lines (35 loc) · 962 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
38
39
40
`timescale 10ns/1ns
module data_memory
// IO ports
(
input wire clk, reset,
input wire [31:0] addr,
input wire [31:0] write_data,
input wire MemRead, MemWrite,
output wire [31:0] read_data
);
// internal signal declaration
reg [7:0] ram [(2^32)-1:0]; // byte addressable memory
wire [31:0] read_word;
integer i;
// body
always @(posedge clk, posedge reset)
begin
if(reset)
ram[i] <= 8'b0;
else
begin
// write operation
if(MemWrite)
begin
ram[addr] <= write_data[7:0];
ram[addr+1] <= write_data[15:8];
ram[addr+2] <= write_data[23:16];
ram[addr+3] <= write_data[31:24];
end
end
end
// read
assign ram_output = {ram[addr+3], ram[addr+2], ram[addr+1], ram[addr]};
assign read_data = MemRead ? ram_output : 32'bx;
endmodule