Basics : Data Types III

Vectors

Vectors can be a net or reg data types. They are declared as [high:low] or [low:high], but the left number is always the MSB of the vector.

wire [7:0] vs; // vs is the MSB.
reg [0:15] vs_1; // vs_1 is the MSB.

In the above examples: If it is written as vs[5:2], it is the part of the entire vector which contains 4 bits in order: vs, vs, vs, vs.

Similarly vs_1[0:7], means the first half part of the vecotr vs_.1
Vector parts can also be specified in a different way:
vector_name[start_bit+:width] : part-select increments from start_bit in above example: vs_1[0:7] is same as vs_1[0+:8].

vector_name[start_bit-:width] : part-select decrements from start_bit in above example: vs[5:2] is same as vs[5-:4].

Arrays

Arrays of reg, integer, real, time, and vectors are allowed. Arrays are declared as follows:

reg vs1[0:7];
real vs3[15:0];
wire [0:3] vs4[7:0]; // Array of vector
integer vs5[0:3][6:0]; // Double dimensional array

Strings

Strings are register data types. For storing a character, we need a 8-bit register data type. So if you want to create string variable of length n. The string should be declared as register data type of length n*8.

reg [8*8-1:0] vs_1; // vs_1 is a string of length 8.

Time Data Types

Time data type is declared using the keyword time. These are generally used to store simulation time. In general it is 64-bit long.

time vs_1;
Vs_1 = \$time; // assigns current simulation time to vs_1.