Blocking and Non-blocking Statements

In Hardware description languages, blocking and non-blocking statements are used to generate either sequential or combinational logic. As the name suggests, a blocking statement blocks the next statement in the queue from executing until the current statement has finished execution. Contradictory to this, a non-blocking statement can execute in parallel with other non-blocking statements. Following symbols are used to denote blocking and non-blocking operations in statements.


1
2
Blocking assignment       =
Nonblocking assignment   <=

During synthesis, a blocking statement infers a wire, while a non-blocking statement infers a latch or a register. Within an always block, blocking statements are generally used for combinational logic implementation, while non- blocking statements are used for sequential logic implementation. Though these two types of statements can be mixed within an always block, it is not advisable as there is a possibility of occuring simulation errors and unwanted latch inferences.

A simple example for the usage of blocking and non-blocking statements is given below.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module blocking_nonblocking_assignments(
    input           clk,
    input           reset,
    input           a_in,
    input           b_in,
    output          c_out,
    output reg      d_out      
    );

    reg             c_temp;
    reg             d_tep;

    //blocking assignment
    always@(posedge clk) begin
        c_temp  =   a_in;      
        c_out   =   c_temp;
    end

    //non_blocking assignment
    always@(posedge clk) begin
        d_temp  <=  b_in;
        d_out   <=  b_temp;
    end

endmodule

In the above example, in the blocking assignment, the output c_out gets the value of the input a_in in the same clock cycle in which the input is sampled. That is, the statements can be assumed as being executed one after the other and hence the input a_in recieved by c_temp and then c_temp is received by the c_out. But in the non-blocking case, the output d_out gets the value of input b_in a clock cycle delayed. The statements can be assumed as being executed in parallel where the current value of b_in is given to d_temp and the current value of d_temp is given to d_out.

In practice, blocking assignments are mostly used in combinational blocks while non blocking assignments are used in sequential blocks


1
2
3
4
5
6
7
8
9
10
11
//combinational block with blocking assignments
always@(*) begin
    b_out = a_in;
    c_out = d_in;
end

//sequential block with non blocking assignments
always@(posedge clk) begin
    b_out <= a_in;
    c_out <= d_in;
end

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.