Blocking assignments help you write simple, step-by-step logic that runs in order. They are best for describing combinational circuits where outputs change immediately when inputs change.
When to use blocking (combinational) in Verilog
always @(*) begin a = b + c; d = a & e; end
Use '=' for blocking assignments inside always blocks.
The statements run in order, one after another.
always @(*) begin
sum = a + b;
carry = (a & b);
endalways @(*) begin temp = x | y; out = ~temp; end
This example shows a combinational logic block using blocking assignment. The output y updates immediately when inputs change.
module comb_logic(input wire a, b, c, output reg y); always @(*) begin y = (a & b) | c; end endmodule // Testbench module test; reg a, b, c; wire y; comb_logic uut(a, b, c, y); initial begin a = 0; b = 0; c = 0; #1 $display("a=%b b=%b c=%b => y=%b", a, b, c, y); a = 1; b = 0; c = 0; #1 $display("a=%b b=%b c=%b => y=%b", a, b, c, y); a = 1; b = 1; c = 0; #1 $display("a=%b b=%b c=%b => y=%b", a, b, c, y); a = 0; b = 0; c = 1; #1 $display("a=%b b=%b c=%b => y=%b", a, b, c, y); end endmodule
Blocking assignments run in order, so the next line sees the updated value immediately.
Use blocking assignments only for combinational logic to avoid simulation mismatches.
Do not mix blocking and non-blocking assignments in the same always block.
Use blocking assignments (=) for combinational logic inside always @(*) blocks.
They execute statements one by one, updating values immediately.
This helps model circuits where outputs depend instantly on inputs.
Practice
always @(*) block to model combinational logic in Verilog?Solution
Step 1: Understand the purpose of
These blocks are used to describe combinational logic where outputs depend immediately on inputs.always @(*)blocksStep 2: Choose the correct assignment type for combinational logic
Blocking assignments (=) execute statements sequentially and update values immediately, which is suitable for combinational logic.Final Answer:
Blocking assignment (=) -> Option CQuick Check:
Combinational logic uses blocking (=) [OK]
- Using non-blocking (<=) in combinational blocks
- Confusing continuous assign with blocking inside always
- Using initial blocks for combinational logic
always @(*) block?Solution
Step 1: Identify the assignment type inside
Blocking assignments use the '=' operator inside procedural blocks.always @(*)Step 2: Match the syntax with blocking assignment
The statementoutput = input + 1;uses '=' which is the blocking assignment syntax.Final Answer:
output = input + 1; -> Option BQuick Check:
Blocking assignment uses '=' inside always blocks [OK]
- Using '<=' instead of '=' inside always @(*)
- Using 'assign' inside procedural blocks
- Using 'initial' for combinational logic
reg a, b, c; always @(*) begin a = 1'b0; b = a; c = b; end
Solution
Step 1: Trace the blocking assignments sequentially
First,a = 0;sets a to 0 immediately. Thenb = a;assigns b the current value of a, which is 0. Finally,c = b;assigns c the current value of b, which is 0.Step 2: Confirm all variables have value 0
All three variables a, b, and c are assigned 0 in order.Final Answer:
a=0, b=0, c=0 -> Option AQuick Check:
Blocking assignments update immediately, so all zero [OK]
- Assuming b or c keep old values
- Confusing blocking with non-blocking timing
- Ignoring sequential order of assignments
always @(*) begin out <= in1 & in2; out2 = out | in3; end
Solution
Step 1: Check assignment types inside
Combinational logic should use blocking assignments (=) consistently insidealways @(*)always @(*)blocks.Step 2: Identify mixed assignment usage
The code uses non-blocking (<=) foroutand blocking (=) forout2, which is incorrect for combinational logic.Final Answer:
Using non-blocking (<=) and blocking (=) mixed in combinational block -> Option AQuick Check:
Combinational blocks use only blocking (=) [OK]
- Mixing <= and = inside combinational blocks
- Forgetting to use always @(*) for combinational logic
- Using continuous assign inside procedural blocks
a and b. Which of the following always @(*) blocks correctly uses blocking assignments to implement this?Solution
Step 1: Confirm the sensitivity list for combinational logic
Usingalways @(*)is preferred for combinational logic to automatically include all inputs.Step 2: Check assignment type for combinational logic
Blocking assignments (=) must be used insidealways @(*)blocks for combinational logic.Step 3: Evaluate each option
always @(*) begin if (a > b) max = a; else max = b; end usesalways @(*)and blocking assignments (=), correctly modeling combinational max logic.Final Answer:
always @(*) begin if (a > b) max = a; else max = b; end -> Option DQuick Check:
Combinational max needs always @(*) and '=' [OK]
- Using non-blocking (<=) in combinational always blocks
- Using explicit sensitivity list instead of @(*)
- Mixing blocking and non-blocking assignments
Ready to prove it?
Pass the test and this pattern moves unknown
