System Verilog Class
System Verilog Class
Example
Requirement:
Create a class called MemTrans that
contains the following members, then
construct a MemTrans object in an initial
block.
a. An 8-bit data_in of logic type
b. A 4-bit address of logic type
c. A void function called print that prints
out the value of data_in and address
Solution:
Class MemTrans;
logic [7:0] data
logic [3:0] addr;
function void print();
$display(data = %h ,data);
$display(addr = %h ,addr);
endfunction
endclass
Top Module
module top;
initial
begin
memTrans obj; //creating an object handle
obj = new(); //Allocating Memory
obj.print();
end
endmodule