Verilog Always block
Always block |
An always block is used to execute a block of statements depending upon if the values of any of the inputs to the block ( called a sensitivity list) changes.
As usual we will first give an example and then give explanation. Let us rewrite the 1 bit comparator we had studied earlier, using always block.
|
We have used always block as follows
always @(x,y);
This essentially means that the code follwed by always statement will run ONLY when the values of the variable x or y changes. We can have more than two variables in the sensitivity list.
One more thing to notice is that the output z has been assigned a reg and not a wire. However, this register will not be really synthesezes to actual register since its value is simple assignment statement depending upon two inputs.
A register variable in verilog simply means a variable that can "hold" value.
The statements in the assigment block are executed sequentially and order does matter. So we will have to be careful about the order.
Multiple statements within the always block are surrounded by begin and end.
The assign statement could also be used as
always @*
The stimulus block stays the same and it is being reproduced below.
|
As usual we get the following result when we compile and run it.
t= 0 x=0,y=0,z=1
t= 20 x=1,y=0,z=0
t= 40 x=1,y=1,z=1
t= 60 x=1,y=0,z=0
The verilog always statement could also be written as
always @( a or b or c)
which is equivalent to
always @( a , b , c)