-
Notifications
You must be signed in to change notification settings - Fork 0
/
ram.v
49 lines (40 loc) · 1 KB
/
ram.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
module RAM(
clk, // Clk input
reset, //Reset input active low
address, // Address Input
data_in, // Data in
write_enb, // Write Enable
read_enb, // Read Enable
data_out // Data out
);
//Input port declaration
input [4:0] address;
input write_enb;
input read_enb;
input [7:0] data_in;
input clk;
input reset;
//Output port declaration
output [7:0] data_out;
//Variable declarations
reg [7:0] data_out ;
reg [7:0] memory [0:31];
//Memory Write Block Write Operation : When write_enb = 1,
always @(posedge clk)
begin
if(!reset)
memory[address] <= 8'bz;
else if(write_enb && !read_enb)
memory[address] <= data_in;
end
//Memory Read Block Read Operation : When read_enb=1
always @(posedge clk)
begin
if(!reset)
data_out <= 8'bz;
else if(read_enb && !write_enb)
data_out <= memory[address];
else
data_out <= 8'bz;
end
endmodule