enum例子
module enum_datatype;
// declaration
enum {red = 0, green = 2, blue = 4, yellow, white = 7, black = 6} Colors;
initial begin
Colors = Colors.first;
for (int i = 0; i < 6; i++) begin
$display("Colors :: Value of %0s \t is = %0d", Colors.name(), Colors);
Colors = Colors.next;
end
end
endmodule
其输出结果为:
下面的例子展示了如何使用enum类型的数据来产生新的数据类型。
module enum_datatype;
//declaration
typedef enum {GOOD, BAD} pkt_type ;
pkt_type pkt_a ;
pkt_type pkt_b ;
initial begin
pkt_a = GOOD ;
pkt_b = BAD ;
if(pkt_a == GOOD)
$display("pkt_a is GOOD packet");
else
$display("plt_a is BAD packet");
if(pkt_b == GOOD)
$display("pkt_b is GOOD packet");
else
$display("pkt_b is BAD packet");
end
endmodule
其输出结果为:
class
class本质是一种包装,对变量和方法进行包装,从而可以获得控制权限。声明一个class使用 class … endclass。
如下例所示:
class packet;
// Properties
bit [31:0] address;
bit [31:0] data ;
// Method
function new();
$display("Inside new Function of packet");
endfunction
endclass : packet
class的详细解释将会在后面提出。