Latest

Verilog Fundamentals · Lesson 1

What Is Verilog? Describing Hardware, Not Writing Software

What a hardware description language is, why Verilog looks like code but behaves like a circuit, and how to run your first design.

4 min read · What you'll learn below

In this lesson you will:
  • Understand what a hardware description language (HDL) is
  • See why Verilog code runs in parallel, unlike software
  • Learn the difference between simulation and synthesis
  • Simulate your first Verilog module

A language for circuits

Modern chips contain millions to billions of transistors. Nobody draws those by hand. Instead, engineers describe the circuit’s behaviour and structure in a hardware description language (HDL), and tools turn that description into gates and, eventually, a layout.

Verilog is one of the two dominant HDLs (the other is VHDL). It was created in the mid-1980s at Gateway Design Automation, standardised by the IEEE as IEEE 1364 in 1995, and later merged into SystemVerilog (IEEE 1800), which is a superset of Verilog. Everything you learn here carries straight over to SystemVerilog.

The big difference: everything happens at once

In software, statements run one after another on a processor. In hardware, every gate is a physical object that is always working, all at the same time.

Consider this Verilog:

assign y = a & b;
assign z = c | d;

These two lines do not run “first y, then z”. They describe two separate gates, an AND gate and an OR gate, that both exist on the chip and both respond instantly whenever their inputs change. The order of the lines does not matter.

Mental model: when you write Verilog, keep asking “what hardware does this line create?”

Simulation vs synthesis

The same Verilog file is used by two very different kinds of tools:

  Simulation Synthesis
Purpose Check that the design behaves correctly Turn the design into real gates
Tools Icarus Verilog, Questa, VCS, Xcelium, Verilator Yosys, Vivado, Quartus, Genus, Design Compiler
Output Waveforms and printed messages A gate-level netlist for an FPGA or chip

Some Verilog constructs only make sense in simulation: printing messages, delays like #10, and reading files. They are used in testbenches, the code that tests your design. The design itself must be written in the synthesizable subset. This course always tells you which is which.

Your first module

Everything in Verilog lives inside a module, a block with inputs and outputs, like a chip with pins. Here is a 2-input AND gate:

// and_gate.v
module and_gate (
  input  wire a,
  input  wire b,
  output wire y
);
  assign y = a & b;   // y is continuously driven by a AND b
endmodule
  • module and_gate (...) names the block and lists its ports.
  • input and output give the direction of each port.
  • assign creates a continuous assignment: y always equals a & b, just like a wire coming out of a real AND gate.

Testing it: a tiny testbench

A testbench is a module with no ports. It creates the design, drives its inputs and watches its outputs:

// and_gate_tb.v
`timescale 1ns/1ps
module and_gate_tb;
  reg  a, b;        // values we will drive
  wire y;           // value the design drives

  and_gate dut (.a(a), .b(b), .y(y));   // "device under test"

  initial begin
    $display(" a b | y");
    a = 0; b = 0; #10 $display(" %b %b | %b", a, b, y);
    a = 0; b = 1; #10 $display(" %b %b | %b", a, b, y);
    a = 1; b = 0; #10 $display(" %b %b | %b", a, b, y);
    a = 1; b = 1; #10 $display(" %b %b | %b", a, b, y);
    $finish;
  end
endmodule

#10 waits 10 time units (10 ns here, set by `timescale), $display prints, and $finish ends the simulation. None of these are hardware; they exist only in simulation.

Run it

In the browser: open EDA Playground, paste the design on the right and the testbench on the left, choose Icarus Verilog as the simulator and click Run.

Locally with Icarus Verilog:

iverilog -o and_sim and_gate.v and_gate_tb.v
vvp and_sim

You should see the AND truth table:

 a b | y
 0 0 | 0
 0 1 | 0
 1 0 | 0
 1 1 | 1

Congratulations, you have described and simulated your first piece of hardware.

Try it yourself: change the design to an XOR gate (assign y = a ^ b;) and rerun the testbench. Which rows of the table change?

Key takeaways

  • Verilog describes hardware. Each statement becomes physical logic that works in parallel.
  • The same code is simulated (to check it) and synthesized (to build it).
  • Designs live in modules with input and output ports.
  • Testbenches drive and observe a design. They use simulation-only features like #delay and $display.

Next lesson: we’ll build bigger circuits out of smaller ones by connecting modules together.