What is a data type in system verilog ?
Data type is specifying the type of data in which the declared variable is capable of holding. If we want to store the integer values in the variable , we need to declare that variable as “int ” data type. If we want to store characters in the varibale , we have to declare the variable as “string” data type. Data type clearly states to the machine that the variable is holding specific type of data to process.
System Verilog provides the following data types :
1 .2-state data types
2. 4- state data types
3. string data types
4. enumeration data types
5. struct
6. typedef
1. 2-state data types :
2- state data types are the data types that have values only ” 0 ” & ” 1 ” . It does’t have the remaining states ” X (unknown) ” & ” Z(high impedance) ” . When X or Z occured those values will be converted to ” 0 ” .
2- state data types are classified as follows :
a.) bit : bit data type is capable of storing single bit value either “0” or “1” . If we want to store values more than 1 we need to declare the variable as vector .
–> vector size of variable is user- defined.
–> default size of bit data type is 1 bit and default value is “0 ” .
Syntax : data_type variable_name;
Example : bit a; // it is capable of holding two values either “0” or “1”
bit [3:0]sum ; // as the variable is declared as vector , it can hold upto 16 values(0 to 15) in the form of bits
b.) byte : Byte data type is capable of storing values in form of bits and it is also having two states “0” & “1”.
–> default size of byte data type is “8 bits ” and default value is “0” .
–> It is capable of storing signed integers in the form of bits.
Syntax : data_type variable_name ;
Example : byte sum; // sum is variable of size 8 bits .
c.) int : “int” data type is a 2-state data type which can store signed integer values .
–> default size of “int” data type is 32 bits and default value is “0”.
Syntax : data_type variable_name;
Example :int tot ; // tot is variable of 32 bits size to hold signed integer values.
d.) shortint : “shortint” data type is a 2-state data type which can hold signed integer values.
–> default size of “shortint” data type is 16 bits and default value is “0”.
Syntax : data_type variable_name ;
Example : shortint sum ; // sum is variable of size 16 bits & stores signed integers
e.) longint : “longint” data type is a 2-state data type which can hold signed integer values.
–> default size of “longint” data type is 64 bits and default value is “0”.
Syntax : data_type variable_name ;
Example : longint sum ; // sum is variable of size 64 bits & stores signed integers