Data types is designed to represent the data storage and transmission elements.Value Set.
Verilog supports four values.
Value Condition in Hardware
0 logic Zero, False condition
1 logic One, True condition
x Unknown logic value
z High impledence/Floating stateThere are two main groups of data types based on way that they are assigned and hold the values, also represent different hardware structures :
1.Net data types.
2.Variable data types
1. Net data Types:
Net is not a keyword, but represents a class of data types such as wire, wand, wor, tri, triand, trior, tri0, tri1 etc.
The net data types shall represent physical connections between structural entities, such as gates.
A net shall not store a value (except for the trireg net).
Value of net is based on drivers, such as a continuous assignment or a gate.
Undriven net shall have a value of high-impedance (z)
wire a; //wire a
wire a = 0; //Wire a, with initialized to ‘0’
2. Variable data types:
Variable is not a keyword, but represents a class of data types such as integer, real, realtime, reg, time etc.
A variable is an abstraction of a data storage element.
it stores the value until next assignment.
Uninitialized value of variables is Unknown Value (x) except real and realtime (shall be 0.0).
Vectors
Sclar – One bit width data type
Vector – multiple bit width data type
Data type (Net/variable) can be decalred as vectors.
if bit width is not specified, default is one bit width.
wirea; //Scalar
wire [2:0] b; //wire b, with width three-bit. Vector
rega; //Scalar
reg [2:0] b; //reg b, with width three-bit. Vector
More on Variable Data Types:
regs/registers:
regs are declared by the keyword reg
default value of reg data type is ‘x’
Integers:
integers are declared by the keyword integer
An integer is a general-purpose variable used for manipulating quantities
time:
A time variable is used for storing and manipulating simulation time quantities (Usefull for debugging purposes)
real:
real are declared by the keyword real
Used to to store real value, can be specified in decimal notation (ex. 1.23) or scentific notaion (ex. 2e3 or 2 X 10^3)
Arrays:
An array is a group of elements that can be 1-bit or n-bit wide.
Array can be dclared for both NET and Variable data types.
Array Declaration:
<data_type> <v_width> <v_name> <v_depth>;
reg var_1; //var with width 1-bit
reg var_2[31:0]; //array of 32 elements with each element width 1-bit
reg var_2[0:31]; //array of 32 elements with each element width 1-bit
reg var_3[32]; //Invalid declaration
reg [1:0] var_4[31:0]; //array of 32 elements with each element width 2-bit
reg [0:1] var_4[31:0]; //array of 32 elements with each element width 2-bit
reg var_5 [1:0][2:0]; //two dimensional array 2×3 with each element width 1-bit
var_5[0][0]
var_5[0][1]
var_5[0][2]
var_5[1][0]
var_5[2][1]
var_5[3][2]
reg [0:1] var_6 [1:0][2:0]; //two dimensional array 2×3 with each element width 2-bit
Array assignmnet:
var_1 = 0;
var_2 = 0; //Invalid assignment – attempt to assign to complete array
var_2[0] = 0; //Assigning ‘0’ to 0th index of array
var_4[2] = 2; //Assigning ‘2’ to 3rd index of array
var_5[1][0] = 1; //Assigning ‘1’ to [0]th index of [1] array
Parameters:
Parameters do not belong to either the variable or the net data type group.
Parameters are not variables, they are constants.
Parameters are declared with the keyword parameter.
parameter abc = 6; //defines abc as constant value 6
parameter def = 6.3; //defines def as real parameter