-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_memory.v
81 lines (61 loc) · 1.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 09/28/2017 12:45:44 AM
// Design Name:
// Module Name: data_memory
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module data_memory(
clk, //clock
addr,
rdata,
wdata,
wren
);
//Following are the input ports to one of the modules.
input clk;
input [31:0] addr;
input [31:0] wdata;
input [3:0] wren;
//The only output port which reads data, is assigned a variable rdata.
output [31:0] rdata;
//We have here 4 memory units, each of which has 65536 (8 bit locations).
reg [7:0] memory_lane0 [65535:0];
reg [7:0] memory_lane1 [65535:0];
reg [7:0] memory_lane2 [65535:0];
reg [7:0] memory_lane3 [65535:0];
//The output port takes up 8 bit from each of the memory unit, adding up to 32 bit data which was supposed to be read.
//This is done using the command assign.
assign rdata = {
memory_lane3[addr[17:2]],
memory_lane2[addr[17:2]],
memory_lane1[addr[17:2]],
memory_lane0[addr[17:2]]
};
//Our operations are active on the rising edge i.e. the positive clock edge.
//If write enable(denoted by wren[i]) is assigned a value 1, the data is assigned to a particular location in the memory unit.
always @(posedge clk)
begin
if (wren[0])
memory_lane0[addr[17:2]] <= wdata[7:0];
if (wren[1])
memory_lane1[addr[17:2]] <= wdata[15:8];
if (wren[2])
memory_lane2[addr[17:2]] <= wdata[23:16];
if (wren[3])
memory_lane3[addr[17:2]] <= wdata[31:24];
end
endmodule