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
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.
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 A
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
Step 1: Check assignment types inside always @(*)
Combinational logic should use blocking assignments (=) consistently inside always @(*) blocks.
Step 2: Identify mixed assignment usage
The code uses non-blocking (<=) for out and blocking (=) for out2, which is incorrect for combinational logic.
Final Answer:
Using non-blocking (<=) and blocking (=) mixed in combinational block -> Option A
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
Step 1: Confirm the sensitivity list for combinational logic
Using always @(*) is preferred for combinational logic to automatically include all inputs.
Step 2: Check assignment type for combinational logic
Blocking assignments (=) must be used inside always @(*) blocks for combinational logic.
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.
Final Answer:
always @(*) begin
if (a > b)
max = a;
else
max = b;
end -> Option D
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 unknownstrongwhile earning +1 Grip toward your certificate.