forked from deoregaurav92/SystemVerilog_Coding_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.sv
44 lines (39 loc) · 1.38 KB
/
mem.sv
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
///////////////////////////////////////////////////////////////////////////
// (c) Copyright 2013 Cadence Design Systems, Inc. All Rights Reserved.
//
// File name : mem.sv
// Title : Memory Module
// Project : SystemVerilog Training
// Created : 2013-4-8
// Description : Defines the memory module
// Notes :
// Synchronous 8x32 Memory Design
// Specification:
// Memory is 8-bits wide and address range is 0 to 31.
// Memory access is synchronous.
// Write data into the memory on posedge of clk when write=1
// Place memory[addr] onto data bus on posedge of clk when read=1
// The read and write signals should not be simultaneously high.
//
///////////////////////////////////////////////////////////////////////////
module mem (
input clk,
input read,
input write,
input logic [4:0] addr ,
input logic [7:0] data_in ,
output logic [7:0] data_out
);
// SYSTEMVERILOG: timeunit and timeprecision specification
timeunit 1ns;
timeprecision 1ns;
// SYSTEMVERILOG: logic data type
logic [7:0] memory [0:31] ;
always @(posedge clk)
if (write && !read)
// SYSTEMVERILOG: time literals
#1 memory[addr] <= data_in; // writing into the memory
// SYSTEMVERILOG: always_ff and iff event control
always_ff @(posedge clk iff ((read == '1)&&(write == '0)) )
data_out <= memory[addr]; // Reading from the memory
endmodule