-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
memory.v
39 lines (33 loc) · 1.15 KB
/
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
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Akilesh Kannan <[email protected]>
//
// File: memory.v
// Modified: 2020-07-15
// Description: General Memory module
// Can be used to build RAM, ROM etc.
//
// License: MIT
//
////////////////////////////////////////////////////////////////////////
`default_nettype None
`timescale 1ns/1ps
module memory #(parameter integer wordSize = 4, parameter integer numWords = 64)(output reg[wordSize-1:0] dataOut, input enable, input[$clog2(numWords)-1:0] address, input[wordSize-1:0] dataIn, input readWrite);
reg[wordSize-1:0] mem[numWords-1:0];
// Whenever there is a change in either enable or readWrite, execute the always block
always @(enable, readWrite) begin
if(enable) begin
/*
readWrite = 1 ==> read;
readWrite = 0 ==> write;
*/
if(readWrite)
dataOut = mem[address];
else
mem[address] = dataIn;
end
// if not enabled, register is not connected
else
dataOut = 64'bz;
end
endmodule