Learn Verilog
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 4 of 7: Combinational Logic
Describe logic whose output depends only on the input values that exist right now.
module mux2 (
input wire a, b, select,
output reg y
);
always @(*) begin
if (select)
y = b;
else
y = a;
end
endmodule
What to notice
- always @(*) automatically includes every read signal in the sensitivity list.
- The if statement chooses b when select is high and a when it is low.
Practice: Add a third input c and turn this into a 3-to-1 multiplexer with two select bits.
How to study each lesson
- Read the concept before copying the example.
- Predict the output or waveform before running the simulator.
- Change one input, parameter, or statement and observe the result.
- Use a self-checking assertion or comparison whenever possible.
- Keep the smallest working example as evidence for the next lesson.