What is the difference between =
and <=
in this code? Also, how do I print the value of data
?
module always_example();
reg clk,reset,enable,q_in,data;
always @ (posedge clk)
if (reset) begin
data <= 0;
end else if (enable) begin
data <= q_in;
end
// if i put $print("data=%d", data); there is error
endmodule
= is blocking statement. In an always
block, the line of code will be executed only after it's previous line has executed. Hence, they happens one after the other, just like combinatoral logics in loop.
<= is non-blocking in nature. This means that in an always
block, every line will be executed in parallel. Hence leading to implementation of sequential elements.