Verilog basics

Learn Verilog

Build a practical foundation in digital design, simulation, and self-checking testbenches.

What you will learn

Work through the lessons in order. Each lesson introduces one idea, shows a focused example, explains the important lines, and gives you a practical exercise.

Start with the learning path

Verilog describes hardware behavior. You will learn how modules, signals, combinational logic, sequential logic, and testbenches work together before moving into SystemVerilog and UVM.

Lesson 7 of 7: Check Results Step by Step

Add simple self-checking logic so a testbench reports a failure instead of relying only on waveforms.

initial begin
  a = 0; b = 0; #1;
  if (y !== 0) $error("0 AND 0 failed");

  a = 1; b = 1; #1;
  if (y !== 1) $error("1 AND 1 failed");

  $display("Test complete");
  $finish;
end

What to notice

  • #1 gives the design time to respond before the check.
  • !== catches unknown X and Z values as well as 0/1 mismatches.
  • $error marks a failed expectation in the simulator log.
Practice: Write all four input checks for the AND gate, then open the finished test in EDA Playground.

How to study each lesson

  1. Read the concept before copying the example.
  2. Predict the output or waveform before running the simulator.
  3. Change one input, parameter, or statement and observe the result.
  4. Use a self-checking assertion or comparison whenever possible.
  5. Keep the smallest working example as evidence for the next lesson.