0
\$\begingroup\$

Consider the following Verilog snippet:

module mod1 ( input clk, input [1:0] a, input [1:0] b, output reg [3:0] c); 
 always @ ( posedge clk)
 begin 
 c <= {c, &a, |b};
 c[0] <= ^c[3:2];
 end
endmodule

In my textbook it says

A group of blocking assignments are evaluated in the order they appear in the code, whilst a group of nonblocking assignments are evaluated concurrently, before any of the statements on the left hand sides are updated.

So what does that mean here? Suppose c = 1100, a = 11 and b = 01 at the beginning. The first statement will read as c = 0011 and the second as c[0] = 0 because the c in the second statement is 1100 since the assignments only take effect after the clock cycle if I understood the textbook correctly. But what is c in the end? Is it 1100 because of the last statement, or is it 0010? Please also explain why.

asked Jul 19, 2021 at 9:21
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Both statements assign a value to c[0], so even with nonblocking assignment, it is the last statement that prevails. This means that |b in the first statement is discarded, and the result will be 0010. The first three bits come from the first statement, and the last bit comes from the second statement, all updated simultaneously.

It could be written as a single, less confusing statement:

c <= {c[1:0], &a, ^c[3:2]};
answered Jul 19, 2021 at 10:31
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.