In reply to W I Master:
I believe you need a good understanding of the active, inactive, and NBA regions before trying to understand the other regions. You do not need to be aware of the other regions for most of the other code you write.
In the code shown below, all statements execute in an active region. Statements schedule future events for the current region, or the inactive, or NBA regions. When its time to execute another region, that region becomes the active region, and process repeats itself.
module top;
bit a,b,c;
/*
always @(a) $display("a changed ",a);
always @(b) $display("b changed ",b);
always @(c) $display("c changed ",c);
*/
always begin
$display("begin of always block a");
@(a) $display("a changed ",a);
end
always begin
$display("begin of always block b");
@(b) $display("a changed ",b);
end
always begin
$display("begin of always block c");
@(c) $display("a changed ",c);
end
initial begin
$display("begin of initial block");
$display("First active region");
$display("blocking assignment");
a = 1;
$display("non-blocking assignment");
b <= 1;
$display("inactive delay statement");
#0
$display("second active region");
$display("blocking assignment");
c = 1;
$display("inactive delay statement");
#0
$display("third active region");
$display("end of initial block");
end
endmodule
All three always blocks and the initial block start as 4 processes in the first active region. The starting order of blocks is indeterminate.
The first active region continues until all four processes have blocked or terminated. When the blocking assignment is made to a, the always @(a) block could resume at any time while the initial block is still executing statements in the first active region. But it must execute before the #0 resumes, starting the second active region. The non-blocking assignment executes in the first active region and schedules an NBA update to b.
When the blocking assignment to c is made in the second active region, the always @(c) block must execute within the current active region. Again, the ordering of statement execution of parallel processes within the same active region is indeterminate.
Then, the initial block process terminates in the third active region. All three always blocks are suspended, so there a re no more active, or inactive events scheduled. So now the NBA update to be executes in the fourth active region, causing the always @(b) block to resume. It executes its display statement and blocks waiting for another change on b.
Finally, all blocks are suspended with no other events to become active, so the simulation terminates.