forked from deoregaurav92/SystemVerilog_Coding_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem_lab7.sv
37 lines (32 loc) · 1.28 KB
/
mem_lab7.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
///////////////////////////////////////////////////////////////////////////
// (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 (mem_inf.mem mbus);
// SYSTEMVERILOG: timeunit and timeprecision specification
timeunit 1ns;
timeprecision 1ns;
// SYSTEMVERILOG: logic data type
logic [7:0] memory [0:31] ;
always @(posedge mbus.clk)
if (mbus.write && !mbus.read)
// SYSTEMVERILOG: time literals
#1 memory[mbus.addr] <= mbus.data_in; // writing into the memory
// SYSTEMVERILOG: always_ff and iff event control
always_ff @(posedge mbus.clk iff ((mbus.read == '1)&&(mbus.write == '0)) )
mbus.data_out <= memory[mbus.addr]; // Reading from the memory
endmodule