Skip navigation.
Home

SystemVerilog Class

The basic syntax for creating a class and creating an instance of the class is demonstrated in this snippet. An instance of the class is created using the new function. Optional values can be passed into the new function. Other functions and tasks can be created inside the class. This example shows a display function.

class TestClass;          // name of class.
 
int integer_a,integer_b;  // sample variables.
 
  function new(int a, int b); // function that is run when instance of object is created.
    integer_a = a;
    integer_b = b;
  endfunction
 
  function display_class();
    $display("integer_a=%d integer_b=%d",integer_a,integer_b);
  endfunction
 
endclass
 
// Simple test bench to exercise the test class.
module tbTestClass;
 
TestClass tc1;  // declare instance of class.
 
initial begin
  tc1 = new(10,20);     // create a new instance of TestClass with sample values.
  tc1.display_class();  // Call the display_class function in TestClass
  $stop;
end
 
endmodule

AttachmentSize
system_verilog_class.sv686 bytes

Interesting information about activation

I think this board is the proper place to ask you about the activation proccess. My link is not working properly, do you know why it is happening? http://www.hdlsnippets.com/?9ce3e50da26f3124e12b5ee5d3d,