There are ways to group a set of statements together that are syntactically equivalent to a single statement and are known as block statements. There are two kinds of block statements: sequential and parallel.
Statements are wrapped using
end keywords and will be executed sequentially in the given order, one after the other. Delay values are treated relative to the time of execution of the previous statement. After all the statements within the block are executed control may be passed elsewhere.
initial begin #10 data = 8'hfe; #20 data = 8'h11; end
In the example above, first statement in the
begin-end block will be executed at 10 time units, and the second statement at 30 time units because of the relative nature. It is 20 time units after the execution of the previous statement.
A parallel block can execute statements concurrently and delay control can be used to provide time-ordering of the assignments. Statements are launched in parallel by wrapping them within the
initial begin #10 data = 8'hfe; fork #20 data = 8'h11; #10 data = 8'h00; join end
In the example above,
fork-join block will be launched after executing the statement at 10 time units. Statements within this block will be executed in parallel and the first statement that will be launched will be the one where data is assigned a value of 8'h00 since the delay for that is 10 time units after the launch of the fork-join. After 10 more time units, the first statement will be launched and data will get the value 8'h11.
initial begin #10 data = 8'hfe; fork #10 data = 8'h11; begin #20 data = 8'h00; #30 data = 8'haa; end join end
There is a
begin-end block in the example above, and all statements within the begin-end block will be executed sequentially, but the block itself will be launched in parallel along with the other statements. So, data will get 8'h11 at 20 time units, 8'h00 at 30 time units and 8'haa at 60 time units.
Naming of blocks
Both sequential and parallel blocks can be named by adding
: name_of_block after the keywords
fork. By doing so, the block can be referenced in a
begin : name_seq [statements] end fork : name_fork [statements] join