quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Class Types

A class is a collection of data and a set of subroutines that operate on that data. The data in a class are referred to as class properties, and its subroutines are called methods. The class properties and methods, taken together, define the contents and capabilities of a class instance or object. Class is same as that found in C++.

   

space.gif

The object-oriented class extension allows objects to be created and destroyed dynamically. Class instances, or objects, can be passed around via object handles, which add a safe-pointer capability to the language. An object can be declared as an argument with direction input, output, inout, or ref. In each case, the argument copied is the object handle, not the contents of the object.

   

space.gif

Class type will be discussed in detail in later chapters.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - class
   

space.gif


  1 module class_data();
  2 
  3 // Class with local fields
  4 class Packet;
  5   int address; 
  6   bit [63:0] data;
  7   shortint crc;
  8 endclass:Packet
  9 
 10 // Class with task
 11 class print;
 12   task print_io (input string msg);
 13     $display("%s",msg); 
 14   endtask:print_io
 15 endclass:print
 16 
 17 // Create instance
 18 Packet p;
 19 print  prn;
 20 
 21 initial begin
 22   // Allocate memory
 23   p = new();
 24   prn = new();
 25   // Assign values
 26   p.address = 32'hDEAD_BEAF;
 27   p.data = {4{16'h55AA}};
 28   p.crc  = 0; 
 29   // Print all the assigned values
 30   $display("p.address = %d p.data = %h p.crc = %d",
 31     p.address, p.data, p.crc);
 32   prn.print_io("Test calling task inside class");
 33   $finish;
 34 end
 35 
 36 endmodule
You could download file class_data.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulator Output
   

space.gif

 p.address =  -559038801 p.data = 55aa55aa55aa55aa p.crc = 0
 Test calling task inside class
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com