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 Enumerations types

Enumerations types are same as that found in other programming language and same as found in C language. Enumerated data types provide the capability to abstractly declare strongly typed variables without either a data type or data value and later add the required data type and value for designs that require more definition.

   

space.gif

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.

   

space.gif

Syntax

   

space.gif

  • enum [ enum_base_type ] { enum_name_declaration { , enum_name_declaration } }
  • enum_base_type ::= integer_atom_type [ signing ] | integer_vector_type [ signing ] [ packed_dimension ] | type_identifier [ packed_dimension ]
  • enum_name_declaration ::= enum_identifier [ [ integral_number [ : integral_number ] ] ] [ = constant_expression ]
   

space.gif

   

space.gif

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

space.gif


  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
   

space.gif

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

space.gif

  state = 0
  color = RED
  medal = BRONZE
  alphabet = c
  newMedal = silver
  Lcolors = yellow
   

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