# Blocking and Nonblocking statements in same procedural block

## Code

module block;
reg a;
reg b = 1'b0;
reg c = 1'b1;

initial begin
c  = b;
a <= c;
end

endmodule


I simulated the code fragment shown in figure expecting the value of a to be 1'b1 because the statement a <= c; is nonblocking and the RHS of the statement is evaluated at the beginning of time step(i.e before execution of c = b;).

But this is the result I obtained. Why is the output a 1'b0 and not 1'b1?

PS: I know it's not a good practice to mix blocking and nonblocking statements in the same block, but I wanted to know how the IEEE std explains this special case.

You have given c a default value of 1, but then at time 0 assign it to be equal to b (blocking). So the simulation copies the value of b to c before sequentially moving on to perform a <= b.

What you have written is essentially:

module block;
reg a;
reg b = 1'b0;
reg c;

initial begin
c  = b;
a <= b;
end

endmodule

• So is it like the initial statement reg c = 1'b0; doesn't have any effect in the code because the blocking statement also covers it's assignment simultaneously? Dec 3, 2014 at 12:59
• @srvn11 yes. initial values assigned like that are often not considered to be synthesizable. Although they probably work for setting FPGA defaults. setting defaults in an initial block for FPGA use is quite common. both types are meaning less for ASIC use, then you should use an active low async reset. Dec 3, 2014 at 14:36
• thank you for the info... I just have one more doubt! The RHS of a nonblocking statement is evaluated at beginning of time step and assigned to LHS at end of time step right? So here value of a should be default value of c i.e 1'bx right? But here it's taking value of b. Dec 4, 2014 at 4:23
• @srvn11 Your description of non-blocking (<=) is correct. But code is executed sequentially, Blocking(=) is placed first so is executed first. And that is why it is bad to mix styles in the same block because if you flip-the order of the statements you get a different behaviour even though you think you describing parallel hardware! Dec 4, 2014 at 9:09