systemverilog学习(2)---- 数据类型(2)

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的详细解释将会在后面提出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值