Recap - Full Testbench
Part of the Fundamentals section of Coddy's Verilog journey — lesson 78 of 90.
Challenge
This challenge tests everything you have learned about testbenches: stimulus, display, monitor, dumpfile, dumpvars, and system tasks. You are given an XOR gate module to test.
What to do:
Create a complete testbench that:
- Declares signals (
regfor inputs,wirefor output) - Instantiates the XOR gate with name
dut - Creates a waveform file named
xor_waveform.vcd - Dumps all signals in the testbench
- Prints a header: "Testing XOR Gate"
- Uses
$monitorto track time, x, y, and z - Tests all four input combinations (00, 01, 10, 11) with
#10delay between each - Prints "Test complete" at the end
- Ends the simulation with
$finish
Try it yourself
module xor_gate (
input x,
input y,
output z
);
assign z = x ^ y;
endmodule
module testbench;
// TODO: Declare reg for x and y
// TODO: Declare wire for z
// TODO: Instantiate xor_gate with name dut
// Connect .x(x), .y(y), .z(z)
initial begin
// TODO: Add $dumpfile "xor_waveform.vcd"
// TODO: Add $dumpvars (0, testbench)
// TODO: Add $display "Testing XOR Gate"
// TODO: Add $monitor for time, x, y, z
// Format: "Time %0t: x=%b, y=%b, z=%b"
// TODO: Add stimulus for all four combinations
// 00, 01, 10, 11 with #10 delay
// TODO: Add $display "Test complete"
// TODO: Add $finish
end
endmoduleAll lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge14Testbench Basics
What Is A TestbenchCreating StimulusDisplay And MonitorDumpfile And DumpvarsUsing System TasksRecap - Full Testbench3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic