-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathram.v
More file actions
executable file
·50 lines (34 loc) · 990 Bytes
/
ram.v
File metadata and controls
executable file
·50 lines (34 loc) · 990 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
41
42
43
44
45
46
47
48
49
50
// RAM MODULE
module ramModule(writeData, writeEnable, addr, readData);
input [7:0] writeData;
input writeEnable;
input [11:0] addr;
output reg [31:0] readData;
reg [12:0] i;
reg [1:0] bitFieldCounter = 0;
(* ramstyle = "M4K" *) reg [31:0] memory [4095:0];
initial // initialize contents of RAM
begin
for(i = 0; i < 4096; i = i + 1)
begin
memory[i] <= 0;
end
end
// occurs when positive edge of clock occurs
always @ (*)
begin
if(writeEnable)
begin
// Write data to memory
if(bitFieldCounter == 0)
memory[addr][7:0] = writeData;
else if(bitFieldCounter == 1)
memory[addr][15:8] = writeData;
else if(bitFieldCounter == 2)
memory[addr][23:16] = writeData;
else
memory[addr][31:24] = writeData;
end
readData = memory[addr];
end
endmodule