2

I'm trying to understand how many flip-flips would this code produce when synthesized?

I've got 2 test cases with non-blocking and blocking assignment code.

Test 1.

wire aclk; 
wire [1:0] a; 
reg [1:0] c; 
reg [1:0] b;

always @(posedge aclk) 
begin 

 b <= a + 1; 
 c = b; 
end

Test 2.

wire aclk; 
wire [1:0] a; 
reg [1:0] c; 
reg [1:0] b;

always @(posedge aclk) 
begin 

 b = a + 1; 
 c <= b; 
end

The Test 1 has 4 FFs and Test 2 has 2 FFs.

I can't understand how does it make a difference I just switching the code.

Thanks for letting me know at all.

2
  • "How many flip-flips..." do you mean "D flip-flops"? Commented Jan 11, 2019 at 23:50
  • because of the bad mix of NBA and BA first test will probably behave differently in simulation and after synthesis. The second will be ok though. do not mix them. Commented Jan 12, 2019 at 4:00

1 Answer 1

5

They are functionally different. Non blocking assignment evaluate the right hand side and then continue to the next statement, storing into the left hand side isn't done until all other statements are evaluated first. Blocking statements evaluate the right hand side and store it into the left hand side immediately.

Test1 is doing this:
evaluate (a+1)
store b into c , BEFORE (a+1) is stored into b!!!
store (a+1) into b

Test2 is doing this:
evaluate (a+1)
store (a+1) into b
store b into c

Like toolic mentioned, you generally used non-blocking statements in sequential logic. Most people also recommend not mixing non-blocking and blocking statements in the same begin-end block.

Sign up to request clarification or add additional context in comments.

2 Comments

Thus, Test2 is equivalent to "store (a+1) into c", and no registers are required for b.
@mkrieger1 I'm confused about Test3 as your comment.

Your Answer

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.