In the below image,there's the code for parity generation. State represented by even_odd and output as z. What will happen if the circled red part as in the image has blocking assignments instead of nonblocking? Will verilog start executing the 2nd always block (the one triggered by change in even_odd) without finishing the execution of 1st always block?
-
2\$\begingroup\$ Interesting question. The example posted is not good to illustrate it though, as the "blocking" assignments in it won't actually block anything and probably won't change the behavior. \$\endgroup\$Eugene Sh.– Eugene Sh.2021年06月28日 15:53:44 +00:00Commented Jun 28, 2021 at 15:53
-
\$\begingroup\$ If I assume there are other statements in the always block, then what will happen? \$\endgroup\$Souhardya Mondal– Souhardya Mondal2021年06月28日 16:59:44 +00:00Commented Jun 28, 2021 at 16:59
-
1\$\begingroup\$ I would really help to post the code as text, not a picture of it. \$\endgroup\$dave_59– dave_592021年06月28日 17:16:47 +00:00Commented Jun 28, 2021 at 17:16
1 Answer 1
It would make a difference if you changed the first always
to blocking assignments to even_odd
and used the value of z
on code that followed the case
statement.
Verilog does not guarantee the order of execution between statements executing in parallel processes. This allows for optimizations that allow even_odd
and z
become the same signal, effectively eliminating the second always
process. So you would have a race condition using blocking assignments.
You would also have a race condition if even_odd
went to any other always @(posedge clk)
process and tried to read it.