Declaring an enum


#1

How do I declare an enum? Is there an easy way to declare an enum range?


Welcome to the discuss.systemverilog.io
#2

Here are a few examples from the SystemVerilog LRM of how to declare an enum

enum {red, yellow, green} light1, light2; // anonymous int type

enum {bronze=3, silver, gold} medal; // silver=4, gold=5

// c is automatically assigned the increment-value of 8 
enum {a=3, b=7, c} alphabet;

// Defining a new data type as an enum
typedef enum logic [2:0] {
  ETH,
  IPV4,
  IPV6,
  UDP,
  TCP,
  ICMP,
  VLAN,
  RSVD
} pkt_hdr_e;

pkt_hdr_e pkt_hdr; // declare variable

Enum Range
This question has been asked here: