Note that, unlike in C, SystemVerilog specifies the number of bits for
the fixed-width types.
logic is a better name than reg, so is preferred. As
we shall see, you can use logic where in the past you have may have used
reg or where you may have used wire.
Typedef
SystemVerilog�s data type system allows you to define quite complex
types. To make this kind of code clear, the typedef
facility was introduced. Typedef allows users to create their own
names for type definitions that they will use frequently in their
code. Typedefs can be very convenient when building up complicated
array definitions.
typedef reg [7:0] octet; octet b;
is the same as
reg [7:0] b;
and
typedef octet [3:0] quadOctet; quadOctet qBytes [1:10];
is the same as
reg [3:0][7:0] qBytes [1:10]; Enum
SystemVerilog also introduces enumerated types, for example
enum { circle, ellipse, freeform } c;
Enumerations allow you to define a data type whose values have
names. Such data types are appropriate and useful for representing
state values, opcodes and other such non-numeric or symbolic data.
Typedef is commonly used together with enum, like this:
typedef enum { circle, ellipse, freeform } ClosedCurve; ClosedCurve c;
The named values of an enumeration type act like constants. The
default type is int. You can copy them to and from
variables of the enumeration type, compare them with one another and
so on. Enumerations are strongly typed. You can�t copy a numeric
value into a variable of enumeration type, unless you use a
type-cast:
c = 2; // ERROR c = ClosedCurve'(2); // Casting � okay
However, when you use an enumeration in an expression, the value you
are working with is the literal�s integer equivalent; so, for
example, it�s okay to compare an enumeration variable with an
integer; and it�s okay to use an enumeration value in an integer
expression.
|
Home |
About Us |
Articles/ Tutorials
| Downloads
| Feedback
| Links
| eBooks
| Privacy Policy |