|
|
Enumerated data types also can be easily referenced or displayed using the enumerated names as opposed to the enumerated values. Unlike typedef, enumerated types needs to be declared first before using them. In the absence of a data type declaration, the default data type shall be int. |
|
|
1 module enum_data();
2
3 enum integer {IDLE=0, GNT0=1, GNT1=2} state;
4 enum {RED,GREEN,ORANGE} color;
5 enum {BRONZE=4, SILVER, GOLD} medal;
6
7 // a=0, b=7, c=8
8 enum {a, b=7, c} alphabet;
9 // Width declaration
10 enum bit [3:0] {bronze='h1, silver, gold='h5} newMedal;
11 // Using enum in typedef
12 typedef enum { red, green, blue, yellow, white, black } Colors;
13
14 Colors Lcolors;
15
16 initial begin
17 state = IDLE;
18 color = RED;
19 medal = BRONZE;
20 alphabet = c;
21 newMedal = silver;
22 Lcolors = yellow;
23 $display (" state = %0d", state);
24 $display (" color = %s", color.name());
25 $display (" medal = %s", medal.name());
26 $display (" alphabet = %s", alphabet.name());
27 $display (" newMedal = %s", newMedal.name());
28 $display (" Lcolors = %s", Lcolors.name());
29 end
30
31 endmodule
You could download file enum_data.sv here
|