Verilog and SystemVerilog Tutorial
Learn Verilog and SystemVerilog step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Verilog? Hardware Description Languages Understand what Verilog and SystemVerilog are, how a hardware description language differs from software, and what a simulator and a synthesizer do with your code.
- The Verilog Design Flow: From Idea to Chip Walk through the hardware design flow: specification, RTL coding, simulation, synthesis, place and route, timing and programming an FPGA, and how to install free tools.
- Your First Verilog Module: A Half Adder Write, read and test your first Verilog design: a half adder module with ports, assign statements, a small testbench, and a C stand-in that checks the truth table.
- Verilog Syntax Basics: Tokens, Comments and Naming Learn the lexical rules of Verilog: whitespace, comments, identifiers, keywords, case sensitivity, compiler directives, system tasks and the style habits that keep code clean.
Modules and Data Types
- Verilog Modules, Ports and Parameters Learn how Verilog modules are declared and instantiated: port directions, ANSI port style, named connections, parameters, localparam, hierarchy and a runnable C parameter stand-in.
- wire, reg, integer and Other Verilog Data Types Understand Verilog nets and variables: wire versus reg, the four logic values 0 1 x z, integer, real, time, tri-state, and a runnable C model of four-state signals.
- Verilog Numbers, Literals and Sizes Master Verilog number literals: size, base and value syntax, binary, hex, decimal, x and z digits, underscores, signed literals, truncation and extension, with runnable C checks.
- Verilog Vectors, Bit-Selects and Concatenation Learn Verilog vectors: declaring buses, selecting bits and slices, indexed part-selects, concatenation and replication, endianness and arrays, with runnable C bit-manipulation checks.
- Verilog Operators: Bitwise, Logical, Reduction and More A complete guide to Verilog operators: arithmetic, bitwise, logical, reduction, shift, relational, equality with x and z, conditional and precedence, with runnable C equivalents.
Combinational Logic
- Continuous Assignments with assign in Verilog Learn how the Verilog assign statement describes combinational logic: continuous assignment, expressions, conditional muxes, implicit wires, multiple drivers and delays.
- Gate-Level Primitives in Verilog Use Verilog's built-in gate primitives and, or, nand, nor, xor, xnor, not, buf and tri-state buffers: syntax, multiple inputs, instance arrays, delays and when to prefer assign.
- Combinational always Blocks: if, case and always @* Write combinational logic in procedural always blocks: sensitivity lists, always @*, always_comb, if/else, case, casez, default values, avoiding latches and a runnable C model.
- Multiplexers, Decoders and Encoders in Verilog Design the classic data-routing blocks in Verilog: multiplexers, demultiplexers, decoders, encoders and priority encoders, with code, wide-bus examples and runnable C models.
- Adders, Subtractors and a Simple ALU in Verilog Build arithmetic hardware in Verilog: ripple-carry adders, carry-lookahead idea, subtractors with two's complement, comparators, flags and a simple parameterized ALU, with C models.
Sequential Logic
- Flip-Flops and always @(posedge clk) in Verilog Learn sequential logic in Verilog: how clocked always blocks describe D flip-flops, registers with enable, edge detection, always_ff, setup and hold timing, with a runnable C clocked-state model.
- Blocking vs Non-Blocking Assignments in Verilog Understand Verilog's two procedural assignments: how = and <= are scheduled, why flip-flops need non-blocking, the shift-register trap, race conditions and the golden coding rules.
- Synchronous and Asynchronous Reset in Verilog Compare synchronous and asynchronous resets in Verilog, write registers with active-low reset, learn reset recovery, a reset synchronizer, and when a register needs no reset at all.
- Counters and Shift Registers in Verilog Design the workhorse sequential blocks in Verilog: binary, up/down, modulo and Gray counters, clock dividers, shift registers, ring and Johnson counters and LFSRs, with C models.
- Register Files, RAM and ROM in Verilog Model storage in Verilog: register files, synchronous single and dual-port RAM, ROM with initial contents, read-during-write behavior, latches versus flip-flops and a small FIFO, with C models.
Testbenches
- Your First Testbench Learn what a Verilog testbench is, how it instantiates a design under test, drives inputs with initial blocks and delays, and why it has no ports or synthesis.
- Stimulus and System Tasks Drive a Verilog design with delays, loops and exhaustive stimulus, and print results with $display, $write, $monitor, $strobe, $time and format specifiers.
- Self-Checking Testbenches Build self-checking Verilog testbenches with reference models, check tasks, error counters and pass/fail summaries instead of reading waveforms by eye.
- Clocks, Resets, Memories and Files in Testbenches Generate clocks and resets in a Verilog testbench, avoid races at clock edges, load test vectors with $readmem and $fopen, and dump waveforms with $dumpvars.
FSMs and Design
- Moore and Mealy State Machines Learn finite state machines in Verilog: states, transitions, Moore and Mealy outputs, state diagrams, and a 101 sequence detector written both ways.
- FSM Coding Styles and State Encoding Compare one-, two- and three-process Verilog FSM styles, learn binary, Gray and one-hot state encoding, default states and safe recovery, with a traffic light example.
- Datapath and Controller Design Split a Verilog design into a datapath of registers and operators and an FSM controller, with a shift-and-add multiplier and a GCD calculator as worked examples.
SystemVerilog Features
- SystemVerilog Data Types: logic, enum, struct and typedef Learn the SystemVerilog data types that replace reg and wire: logic, bit, int, typedef, enum, packed struct, unions and arrays, with C stand-ins for packing.
- always_comb, always_ff, Packages and Functions in SystemVerilog Use SystemVerilog always_comb, always_ff and always_latch to state your intent, write unique and priority case statements, and share types and functions with packages.
- Interfaces, Modports and Clocking Blocks Bundle signals with SystemVerilog interfaces, restrict direction with modports, share tasks, connect testbenches with virtual interfaces and avoid races with clocking blocks.
- Classes and Constrained Randomization Learn SystemVerilog classes for verification: objects, inheritance, rand and randc variables, constraints, randomize(), mailboxes, covergroups and a mini scoreboard.
Synthesis and Verification
- The Synthesizable Subset and Common Pitfalls Learn which Verilog constructs synthesize into hardware and which are simulation-only, plus classic bugs: latches, blocking versus non-blocking, width and sign mismatches.
- Timing, Metastability and Clock Domain Crossing Understand setup and hold time, critical paths and maximum clock frequency, metastability, two-flop synchronizers, Gray-coded pointers and handshakes for clock domain crossing.
- Assertions (SVA) and Functional Coverage Write SystemVerilog assertions with immediate and concurrent assert, property, sequence, implication and delays, and measure test quality with cover and covergroups.
Projects and Practice
- Project: An 8-bit ALU with Flags and a Testbench Design an 8-bit Verilog ALU with add, subtract, logic and shift operations and zero, negative, carry and overflow flags, then verify it against a reference model.
- Project: A UART Transmitter and Receiver Build a UART in Verilog with a baud rate generator, an 8N1 transmitter FSM and a receiver that samples mid-bit, and study the frame format with C stand-ins.
- Project: A Synchronous FIFO Design a synchronous FIFO in Verilog with read and write pointers, full and empty detection using an extra pointer bit, a self-checking testbench and a depth calculation.
- Practice: Verilog Exercises and Interview Questions Twelve Verilog practice problems with solutions and common interview questions: encoders, parity, Gray code, LFSR, edge detector, debouncer, clock divider and more.