0% found this document useful (0 votes)
22 views3 pages

Enum SV

Uploaded by

sadgunanissy662
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Enum SV

Uploaded by

sadgunanissy662
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Day 4/75 VLSI SYSTEM VERILOG By: Abhishek Sorte

Enumeration:

- Enum is a datatype that holds the list of values.


- We can also say that the enum is nothing but the collection of indices.
- Default datatype of enum is “int”, that means by default enum indexes are of int
type.
- Keyword: enum
- Syntax: enum {index_0,index_1,index_2,index_3,…} variable_name;
- Whatever the constant name present inside enum { }, by default value if first
constant is 0 and then it si incremented by 1.
- Example: https://edaplayground.com/x/fT7k

Output:

- In the above example indexing for the constants starts from 0, so the constants
indexing is read = 0, write = 1, busy = 2, empty = 3.

Can we change the indexing of constants in the enum?

- YES, the indexing of the constants in the enum variable can be changed just by
inserting the index value.
- indexing can be changed just by adding a "= index value" in enum declaration
- Example: https://edaplayground.com/x/tt2d

Page 1|3
Day 4/75 VLSI SYSTEM VERILOG By: Abhishek Sorte

Output:

- In the above example we can see that the index numbers are provided to the
constants at the time of enum declaration, because of that the default indexing is
overridden by the custom user defined index values.
- We have not given any index value to read, so by default it will get the index #0,
unlikely we have provided index number 5 to write so in the output it is showing
write at index #5, again busy will get the next index number i.e., index #6. At last we
have given the index number 9 to the empty so it showing index #9.
- This is how we can change the default indexing in enum.

Inbuild methods present for enum:

- Enum has following inbuild methods:


o first : return the 1st element
o last : return the last value
o next : return next element
o prev : return previous element
o next(N) : return next Nth element
o prev(N) : return previous Nth element
- Example: https://edaplayground.com/x/GmQY

Page 2|3
Day 4/75 VLSI SYSTEM VERILOG By: Abhishek Sorte

Output:

NOTE

- The prev(N) and next(N) methods works in the cyclic manner.


- All methods work on the order of the constants and not on the index numbers

Application of Enum:

- In FSM many states are present with different names like IDLE, STATE0, STATE1, etc.
- Before in Verilog we used parameters to declare these states and we assign some
values to it in sequence like 000, 001, 010,…, so on based on the number of states
required.
- Instead of that now enum datatype can be used.
- For this datatype we just have to write the names of the states.
- Values of the states will start from 0 (as we seen default indexing for the enum start
with 0), and it incremented by 1 for each state just like we seen in very 1st example.

Page 3|3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy