-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathram.v
62 lines (62 loc) · 2.46 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
50
51
52
53
54
55
56
57
58
59
60
61
62
// --------------------------------------------------------------------------- //
module ram (clk,reset, writeEn,readEn,writeAddr,readAddr,dataIn,dataOut);
// -------------------------- Parameters declarations ------------------------ //
// data bits number
parameter dataWidth = 100;
// address bits number
parameter addressWidth = 4;
// ------------------- Clock and Reset signal declarations ------------------- //
// clock input
input clk;
// reset input
input reset;
// --------------------------- Input Ports ----------------------------------- //
// write enable;
input writeEn;
// read enable
input readEn;
// writting address ..
input [addressWidth-1:0] writeAddr;
// reading address
input [addressWidth-1:0] readAddr;
// Input data to be written
input [dataWidth-1:0] dataIn;
// ------------------------------ Output Ports ------------------------------- //
// output data to be read
output [dataWidth-1:0] dataOut;
// ------------------------ Register Declarations ---------------------------- //
// ram is an array with ( width = dataWidth & size 2^addressWidth-1 )
reg [dataWidth-1:0] ram[2**addressWidth-1:0];
reg [dataWidth-1:0] dataOut;
// ------------------ Wire Declarations--------------------------------------- //
wire [dataWidth-1:0] dataIn;
// -------------------------------- Logic ------------------------------------ //
//initial
// begin
// dataOut <= 0;
// end
always @(posedge clk or negedge reset)
begin
// ---------------------------- reset all registers ---------------------- //
if( !reset)
begin
dataOut <= 0;
end
// --------------------------------------------------------------------- //
else
// --------------------------------------------------------------------- //
begin
// ---------------------------- write process ------------------------- //
if (writeEn)
ram[writeAddr] <= dataIn;
// --------------------------------------------------------------------- //
// ----------------------------- read process -------------------------- //
if (readEn)
dataOut <= ram[readAddr];
// --------------------------------------------------------------------- //
end
// ----------------------------------------------------------------------- //
end
// ------------------------------------------------------------------------- //
endmodule
// --------------------------------------------------------------------------- //