-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMEM.V
76 lines (57 loc) · 1.55 KB
/
MEM.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
/****************************************************************************************
MODULE: Sub Level Memory Block
FILE NAME: mem.v
VERSION: 1.0
DATE: September 28th, 2001
AUTHOR: Hossein Amidi
COMPANY: California Unique Electrical Co.
CODE TYPE: Behavioral Level
Instantiations:
DESCRIPTION:
Sub Level Behavioral Memory Block, It uses 12 Address and 16 Data Line
the memory size would be 2 ^ 12 = 4096 * 16-bit wide = 65536 bits.
65536 bits / 8 = 8192 Byte -> 8K Byte of memory.
This memory is organized as 4096 locations of 16-bit (2 Byte) wide.
Hossein Amidi
(C) September 2001
California Unique Electric
***************************************************************************************/
`timescale 1ns / 1ps
module MEM (// Input
DataIn,
Address,
MemReq,
RdWrBar,
clock,
// Output
DataOut
);
// Parameter
parameter words = 4096;
parameter AccessTime = 0;
parameter DataWidth = 32;
parameter AddrWidth = 24;
// Input
input [DataWidth - 1 : 0] DataIn;
input [AddrWidth - 1 : 0] Address;
input MemReq;
input RdWrBar;
input clock;
// Output
output [DataWidth - 1 : 0] DataOut;
// Internal Memory Declerations
// 4096 x 16 bit wide
reg [DataWidth - 1 : 0] MEM_Data [0:words-1];
// Signal Declerations
wire [DataWidth - 1 : 0] Data;
// Assignments
// Read Cycle
assign Data = (MemReq && RdWrBar)? MEM_Data [Address]:32'hz;
assign #AccessTime DataOut = Data; // Delay in a continuous assign
// Write Cycle
always @(posedge clock)
begin
if(MemReq && ~RdWrBar)
MEM_Data [Address] <= DataIn;
end
endmodule