Challenge - 5 Problems
Verilog Automatic Result Checker
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of automatic result checking with simple comparator
What is the output of this Verilog testbench snippet that compares expected and actual results automatically?
module test;
reg [3:0] expected = 4'b1010;
reg [3:0] actual = 4'b1010;
initial begin
if (expected === actual) $display("PASS");
else $display("FAIL");
end
endmoduleVerilog
module test; reg [3:0] expected = 4'b1010; reg [3:0] actual = 4'b1010; initial begin if (expected === actual) $display("PASS"); else $display("FAIL"); end endmodule
Attempts:
2 left
💡 Hint
Check if the expected and actual values are exactly the same using the === operator.
✗ Incorrect
The === operator in Verilog checks for exact equality including X and Z states. Since expected and actual are both 4'b1010, the condition is true and "PASS" is printed.
❓ Predict Output
intermediateResult of automatic checking with mismatch
What will this Verilog code print when actual does not match expected?
module test;
reg [3:0] expected = 4'b1100;
reg [3:0] actual = 4'b1000;
initial begin
if (expected === actual) $display("PASS");
else $display("FAIL");
end
endmoduleVerilog
module test; reg [3:0] expected = 4'b1100; reg [3:0] actual = 4'b1000; initial begin if (expected === actual) $display("PASS"); else $display("FAIL"); end endmodule
Attempts:
2 left
💡 Hint
Compare the bits of expected and actual carefully.
✗ Incorrect
Since expected is 1100 and actual is 1000, they differ in the second bit. The === operator returns false, so "FAIL" is printed.
🔧 Debug
advancedIdentify the error in automatic result checking code
This Verilog code is intended to automatically check if actual matches expected and print the result. What error will it cause?
module test;
reg [3:0] expected = 4'b1010;
reg [3:0] actual = 4'b1010;
initial begin
if (expected = actual) $display("PASS");
else $display("FAIL");
end
endmoduleVerilog
module test; reg [3:0] expected = 4'b1010; reg [3:0] actual = 4'b1010; initial begin if (expected = actual) $display("PASS"); else $display("FAIL"); end endmodule
Attempts:
2 left
💡 Hint
Check the difference between assignment and comparison operators in conditions.
✗ Incorrect
The code uses '=' (assignment) instead of '==' or '===' (comparison) in the if condition, which is a syntax error in Verilog.
❓ Predict Output
advancedOutput of automatic checking with unknown bits
What will this Verilog code print when expected has unknown bits (X)?
module test;
reg [3:0] expected = 4'b10X0;
reg [3:0] actual = 4'b1010;
initial begin
if (expected === actual) $display("PASS");
else $display("FAIL");
end
endmoduleVerilog
module test; reg [3:0] expected = 4'b10X0; reg [3:0] actual = 4'b1010; initial begin if (expected === actual) $display("PASS"); else $display("FAIL"); end endmodule
Attempts:
2 left
💡 Hint
The === operator compares unknown bits strictly.
✗ Incorrect
The expected value has an X bit, so expected === actual is false because actual has a 1 in that bit. The code prints "FAIL".
🧠 Conceptual
expertBest practice for automatic result checking in Verilog testbenches
Which of the following is the best practice for automatic result checking in Verilog testbenches to ensure reliable verification?
Attempts:
2 left
💡 Hint
Consider how unknown bits affect comparison results.
✗ Incorrect
Using the === operator ensures that unknown (X) and high-impedance (Z) bits are compared exactly, which is important for reliable automatic checking.
