Bird
Raised Fist0
Verilogprogramming~10 mins

When to use blocking (combinational) in Verilog - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - When to use blocking (combinational)
Start Combinational Logic
↓
Use Blocking Assignments (=)
↓
Evaluate statements in order
↓
Update variables immediately
↓
Output combinational signals
↓
End Combinational Logic
Blocking assignments (=) are used in combinational logic to evaluate statements in order and update variables immediately, reflecting real combinational behavior.
Execution Sample
Verilog
always @(*) begin
  a = b + c;
  d = a + 1;
end
This code uses blocking assignments to compute 'a' then 'd' in order, modeling combinational logic.
Execution Table
StepStatementVariable BeforeEvaluationVariable After
1a = b + c;b=2, c=3, a=0a = 2 + 3a=5
2d = a + 1;a=5, d=0d = 5 + 1d=6
3End always blocka=5, d=6No changea=5, d=6
💡 All statements executed in order with blocking assignments, variables updated immediately.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
a0555
d0066
b2222
c3333
Key Moments - 2 Insights
Why do we use blocking assignments (=) in combinational logic?
Because blocking assignments update variables immediately in order, matching how combinational logic works, as shown in execution_table steps 1 and 2.
What happens if we use non-blocking assignments (<=) in combinational logic?
Non-blocking assignments delay updates until the end of the time step, which can cause incorrect intermediate values in combinational logic, unlike the immediate updates seen in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'a' after step 1?
A0
B5
C6
D2
💡 Hint
Refer to the 'Variable After' column in row for step 1.
At which step does 'd' get its final value?
AStep 2
BStep 1
CStep 3
DNever
💡 Hint
Check the 'Variable After' column for 'd' in each step.
If we replaced '=' with '<=' in the code, how would the variable updates change?
AVariables update immediately in order
BVariables update randomly
CVariables update only at the end of the block
DVariables do not update
💡 Hint
See key_moments explanation about non-blocking assignments delaying updates.
Concept Snapshot
Use blocking assignments (=) in combinational always blocks.
Statements execute in order, variables update immediately.
This models real combinational logic behavior.
Avoid non-blocking (<=) in combinational logic to prevent incorrect delays.
Example:
always @(*) begin a = b + c; d = a + 1; end
Full Transcript
In Verilog, blocking assignments (=) are used in combinational logic blocks to ensure statements execute in order and variables update immediately. This matches how combinational circuits work in hardware. For example, in the code 'always @(*) begin a = b + c; d = a + 1; end', 'a' is updated first, then 'd' uses the new value of 'a'. The execution table shows step-by-step how variables change. Using non-blocking assignments (<=) here would delay updates and cause incorrect behavior. Remember to use blocking assignments for combinational logic to model immediate updates and ordered execution.

Practice

(1/5)
1. Which type of assignment should you use inside an always @(*) block to model combinational logic in Verilog?
easy
A. Continuous assignment (assign)
B. Non-blocking assignment (<=)
C. Blocking assignment (=)
D. Initial assignment

Solution

  1. Step 1: Understand the purpose of always @(*) blocks

    These blocks are used to describe combinational logic where outputs depend immediately on inputs.
  2. Step 2: Choose the correct assignment type for combinational logic

    Blocking assignments (=) execute statements sequentially and update values immediately, which is suitable for combinational logic.
  3. Final Answer:

    Blocking assignment (=) -> Option C
  4. Quick Check:

    Combinational logic uses blocking (=) [OK]
Hint: Use '=' in always @(*) for immediate updates [OK]
Common Mistakes:
  • Using non-blocking (<=) in combinational blocks
  • Confusing continuous assign with blocking inside always
  • Using initial blocks for combinational logic
2. Which of the following is the correct syntax for a blocking assignment inside an always @(*) block?
easy
A. output <= input + 1;
B. output = input + 1;
C. assign output = input + 1;
D. initial output = input + 1;

Solution

  1. Step 1: Identify the assignment type inside always @(*)

    Blocking assignments use the '=' operator inside procedural blocks.
  2. Step 2: Match the syntax with blocking assignment

    The statement output = input + 1; uses '=' which is the blocking assignment syntax.
  3. Final Answer:

    output = input + 1; -> Option B
  4. Quick Check:

    Blocking assignment uses '=' inside always blocks [OK]
Hint: Inside always @(*), use '=' for blocking assignments [OK]
Common Mistakes:
  • Using '<=' instead of '=' inside always @(*)
  • Using 'assign' inside procedural blocks
  • Using 'initial' for combinational logic
3. What is the output of the following Verilog code snippet?
reg a, b, c;
always @(*) begin
  a = 1'b0;
  b = a;
  c = b;
end
medium
A. a=0, b=0, c=0
B. a=0, b=1, c=1
C. a=1, b=0, c=0
D. a=1, b=1, c=1

Solution

  1. Step 1: Trace the blocking assignments sequentially

    First, a = 0; sets a to 0 immediately. Then b = a; assigns b the current value of a, which is 0. Finally, c = b; assigns c the current value of b, which is 0.
  2. Step 2: Confirm all variables have value 0

    All three variables a, b, and c are assigned 0 in order.
  3. Final Answer:

    a=0, b=0, c=0 -> Option A
  4. Quick Check:

    Blocking assignments update immediately, so all zero [OK]
Hint: Blocking updates happen immediately in order [OK]
Common Mistakes:
  • Assuming b or c keep old values
  • Confusing blocking with non-blocking timing
  • Ignoring sequential order of assignments
4. Identify the error in this combinational logic block:
always @(*) begin
  out <= in1 & in2;
  out2 = out | in3;
end
medium
A. Using non-blocking (<=) and blocking (=) mixed in combinational block
B. Missing sensitivity list
C. Using continuous assignment inside always block
D. No error, code is correct

Solution

  1. Step 1: Check assignment types inside always @(*)

    Combinational logic should use blocking assignments (=) consistently inside always @(*) blocks.
  2. Step 2: Identify mixed assignment usage

    The code uses non-blocking (<=) for out and blocking (=) for out2, which is incorrect for combinational logic.
  3. Final Answer:

    Using non-blocking (<=) and blocking (=) mixed in combinational block -> Option A
  4. Quick Check:

    Combinational blocks use only blocking (=) [OK]
Hint: Use only '=' in combinational always blocks [OK]
Common Mistakes:
  • Mixing <= and = inside combinational blocks
  • Forgetting to use always @(*) for combinational logic
  • Using continuous assign inside procedural blocks
5. You want to design a combinational logic block that calculates the maximum of two inputs a and b. Which of the following always @(*) blocks correctly uses blocking assignments to implement this?
hard
A. always @(*) begin if (a > b) max <= a; else max <= b; end
B. always @(a or b) begin if (a > b) max = a; else max = b; end
C. always @(a or b) begin if (a > b) max <= a; else max <= b; end
D. always @(*) begin if (a > b) max = a; else max = b; end

Solution

  1. Step 1: Confirm the sensitivity list for combinational logic

    Using always @(*) is preferred for combinational logic to automatically include all inputs.
  2. Step 2: Check assignment type for combinational logic

    Blocking assignments (=) must be used inside always @(*) blocks for combinational logic.
  3. Step 3: Evaluate each option

    always @(*) begin if (a > b) max = a; else max = b; end uses always @(*) and blocking assignments (=), correctly modeling combinational max logic.
  4. Final Answer:

    always @(*) begin if (a > b) max = a; else max = b; end -> Option D
  5. Quick Check:

    Combinational max needs always @(*) and '=' [OK]
Hint: Use always @(*) with '=' for combinational max logic [OK]
Common Mistakes:
  • Using non-blocking (<=) in combinational always blocks
  • Using explicit sensitivity list instead of @(*)
  • Mixing blocking and non-blocking assignments
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard