# Sequence of evaluation in the following non blocking code?

I have the following verilog code that I came across and trying to find the sequence of evaluation. What value does 'A' have at the end of a cycle and after 5 cycles, when the value of A is 'x' at cycle 0.

always @ (posedge clk)

A <= 1;
A <= A+1;
B <= A+1;


I understand that the evaluation of RHS is done on the posedge and the assignment happens at the end of the cycle. What value would A have after the assignment? Is it '1' or 'X'?

Also does adding the delay to the statements act as blocking for the following code?

always @ (posedge clk)
begin
#5 A<=1;
#5 A<=A+1;
B <=A+1;
end

• I edited your post to format the code blocks. Please check for correctness. I did remove two leading slashes on the lines starting with #, since I assume you put them there to avoid formatting the lines as headings, right? – Justin Mar 4 at 21:44
• You are missing th begin/end block. Is it intended? – Eugene Sh. Mar 4 at 21:46
• Thanks @Justin for the edit, This interface is new to me. Missing begin/end block was intentional @Eugene Sh. – sxa144 Mar 4 at 22:20

I assume there is a begin/end around the three assigment statements. Otherwise the code is legal.

Because you are using non-blocking assignments (NBA) in your first example, A has the old value throughout the current time step. If you have 2 NBA to the same variable in the same timestep, the last one wins. So at the end of the timestep, A has the value A+1. After 5 cycles, it has the value A+5 Since you didn't specify how A gets initialized, that's the best answer you can get. Also realize that your code (enclosed by a single begin/end)is equivalent to

always @ (posedge clk) A <= 1;
always @ (posedge clk) A <= A+1;
always @ (posedge clk) B <= A+1;


In the second example when executing A<=A+1, A already is already updated to its new value, 1, so A would be 2. Note that blocking delays would not be allowed in synthesizable code.

• Agree, So the value to B gets assigned before the blocking delay statements are evaluated or after ? – sxa144 Mar 4 at 22:57
• There is no blocking delay between the second assignment to A and the assignment to B. You should try experimenting. – dave_59 Mar 4 at 23:08