Verilog Vectors
In Verilog we have seen that we have 1-bit data types. But in hardware, many ports can have more than one bit has an input. Also, it can have registers which is nothing but a group of flip flops. Thus, Verilog provides us a way to use both single bit variables and multiple bits variable.
Scalar variables
Any reg or wire declaration, that has only one bit is known as scalar variables.
Vector variables
Any reg or wire declaration that has more than one bit is known as vector variables. The range is specified using [msb:lsb] or [lsb:msb] brackets just after writing the data type.
Vector Slicing
Any subpart of the vectors can be selected, and this is known as vector slicing. After declaring a vector, subpart can be selected using the [] brackets and providing the range in between.
Vector slicing should be in the same order as it is declared. It means that the if during declaration msb is written first then, during slicing should be done from higher bits to lower bits and vice-versa.
Syntax for vector slicing:
[<higer-bit>:<lower_bit>] or
[<lower_bit>:<higer-bit>]
A disadvantage of this method is that we can't have a variable as a slicing parameter. Slicing parameter should always be constant.
So, Verilog provides a one more way to slice vectors, in which we can use variables as parameter. Verilog provides +: and -: operators for slicing.
Syntax for using this slicing operator:
[<starting_bit>+:<width>]
[<starting_bit>-:<width>]