RTL FOUNDATIONS · F01

RTL and Hardware Thinking: How Does a Description Become a Circuit?

From a selection requirement to a circuit description and tests you can rerun.

25 November 2026No Verilog prerequisiteFilm and complete source included

Previous lesson: F00 RTL Syntax Primer · View the RTL Foundations course

A device monitors two sensor locations. Each sensor has already converted its reading into a digital overtemperature flag. Location A reports 0, and location B reports 1. The front panel has one status output, so an operator chooses which location to display.

That small requirement is enough to start designing hardware. We need two data inputs, a selection input and an output. We can describe their relationship in RTL, then test whether the connections deliver the required result.

This lesson builds a one-bit selector from the beginning. It introduces modules, ports, instances and continuous assignment, then uses a testbench to expose a deliberately incorrect version.

Follow the circuit in the lesson film

The film follows selection, connections, testing and synthesis. Jump to a chapter, then return to the exercise to change the inputs yourself.

Film chapters

Download MP4
Download captions VTT
Read the film transcript

Gemini TTS provides the US English narration. The animation illustrates signal relationships; actual RTL simulation results and source files are available below.

Two sensor locations, one status output

The sensor outputs are already digital: 0 means no overtemperature condition, and 1 means an overtemperature condition. We will select between those signals. Designing the analog sensing circuitry is a separate task.

Call the inputs a_i and b_i. The control input is sel_i, and the output is selected_o. In this lesson, the suffixes _i and _o identify inputs and outputs. They are naming conventions, not Verilog keywords.

The requirement is short: when sel_i=0, the output follows A. When sel_i=1, it follows B. A circuit that selects one of several data inputs is a multiplexer, usually shortened to mux.

One-bit inputs A and B feed a mux. A select input enters below it, and selected exits to the right. Select zero chooses A; select one chooses B.
A and B carry the data. The select input determines which source reaches the output.

Choosing A does not force the output to 1. If A is currently 0, selecting A must produce 0. Selection identifies the source; that source supplies the value. The four cases below deliberately make A and B different so a selection error is visible.

ABselRequired sourceExpected output
010A0
100A1
101B0
011B1

Try the controls below. For each input change, identify the selected source and then read its value.

Change the inputs and follow the selected source

Toggle each signal between 0 and 1, then try the swapped-input version. The table keeps the original specification as its expected answer.

All eight binary combinations of three one-bit inputs
ABselExpectedActualCheck
0000Not runPending
0100Not runPending
1001Not runPending
1101Not runPending
0010Not runPending
0111Not runPending
1010Not runPending
1111Not runPending

This browser exercise models binary values; it does not execute Verilog. The downloadable testbench runs in Icarus Verilog.

A module describes the circuit and its ports

A module gives a hardware description a name and an interface. Other parts of a design connect signals through that interface. Its connection points are called ports.

Here is the complete functional body. The download also includes directives that help catch undeclared signals; the selection function remains the same single assignment.

module channel_select_1b (
    input  wire a_i,
    input  wire b_i,
    input  wire sel_i,
    output wire selected_o
);
    assign selected_o = sel_i ? b_i : a_i;
endmodule

module channel_select_1b names the description. The input and output declarations identify signal directions. wire declares a net used for connections. No bit range is specified, so each port is one bit wide, enough for the 0 and 1 values in our example.

A semicolon ends a declaration or statement. endmodule ends the module description. Recognizing those boundaries makes it easier to separate the interface from the relationship being implemented.

Placing the module inside another design creates an instance of that description. This instance is named u_select:

channel_select_1b u_select (
    .a_i(sensor_a),
    .b_i(sensor_b),
    .sel_i(channel_sel),
    .selected_o(panel_status)
);

.a_i(sensor_a) connects the instance’s a_i port to the surrounding design’s sensor_a signal. The name after the dot belongs to the module interface. The name in parentheses belongs to the surrounding design. They can differ while the connection remains explicit.

This is a connection fragment intended to sit inside another module, which declares the surrounding signals. The testbench later provides a complete runnable example. The instance does not call a CPU function once. It describes hardware that remains connected to those signals.

Continuous assignment keeps the relationship active

The functional line is:

assign selected_o = sel_i ? b_i : a_i;

? : is the conditional operator. The expression after ? is selected when the condition is true; the expression after : is selected when it is false. We restrict this first example to known binary inputs, so sel_i=1 chooses B and sel_i=0 chooses A. The next lesson introduces unknown values in four-state simulation.

assign is a continuous assignment. It connects the output to the expression on the right. When an input changes, the described circuit responds, and a simulator reevaluates the relationship. The testbench has a different role: it schedules one set of input values, then another. [1]

The mux is combinational logic. Its output depends on the current A, B and select values. It does not need the previous input combination. The same current inputs produce the same settled logical result.

The inverse of select is ANDed with A. Select is ANDed with B. The two branches are ORed, implementing the same mux function.
One equivalent gate expansion enables the A branch for select zero and the B branch for select one.

The diagram expands the function into NOT, AND and OR operations to make the paths visible. A synthesis tool can keep a higher-level mux representation before choosing an implementation for a target. The RTL defines the required relationship; the tool, target and constraints influence the eventual components.

Two instances do not take turns

Suppose a logging connection needs the same selected status as the panel. We can describe two instances with the same inputs and separate outputs:

module parallel_top (
    input wire a_i, b_i, sel_i,
    output wire panel_o, logger_o
);
    channel_select_1b u_panel (.a_i(a_i), .b_i(b_i), .sel_i(sel_i), .selected_o(panel_o));
    channel_select_1b u_logger (.a_i(a_i), .b_i(b_i), .sel_i(sel_i), .selected_o(logger_o));
endmodule

u_panel and u_logger are distinct instance names. Both receive A, B and select. Their order in the source does not make one circuit wait for the other to execute. Both outputs are evaluated from the current inputs.

The same A, B and select signals feed separate mux instances u_panel and u_logger. Their outputs go to the panel and logger; neither instance feeds the other.
The instances receive the same inputs. The source listing does not schedule the logger after the panel.

This diagram shows RTL connectivity. Synthesis may merge equivalent logic, so counting instances does not establish that the final chip contains independent copies. Later lessons on redundancy and common-cause failures will therefore inspect the synthesized structure as well.

The testbench compares behavior with the requirement

We already have four expected results. A testbench applies those inputs, allows simulation evaluation to settle and compares the output with the expectation. The circuit under test is often called the DUT, or design under test. Here it is an instance of channel_select_1b.

tb_channel_select_1b.sv declares inputs that its test procedure can change, then connects them to the DUT through named ports. The directed test applies our four cases:

check(0, 1, 0, 0);
check(1, 0, 0, 1);
check(1, 0, 1, 0);
check(0, 1, 1, 1);

The arguments are A, B, select and expected output, in that order. Expected outputs come from the requirement table. The test does not copy the DUT’s output and call it the answer. Each check applies inputs, waits #5, then compares. The !== comparison prevents an unknown output from silently passing as an expected binary value.

Four observation intervals show A as 0,1,1,0; B as 1,0,0,1; select as 0,0,1,1; and the output as 0,1,0,1. There is no clock signal.
A binary timing illustration of the four directed cases. The intervals are scheduled by the testbench, without adding a clock.

The testbench declares a time unit of 1 ns, so #5 leaves 5 ns between observations. That wait is in the testbench, not the mux. It does not measure or specify a 5 ns physical mux delay. This RTL model assigns no physical gate delays.

The generated VCD file records simulated signal changes for a waveform viewer. Those values help check the function. Actual propagation time requires target components, interconnect and timing analysis.

Which tests reveal swapped inputs?

The deliberately incorrect version swaps the conditional operator’s data expressions:

assign selected_o = sel_i ? a_i : b_i;

For A=0, B=1 and select=0, the requirement calls for A, giving 0. The incorrect version produces B’s 1. That is a concrete counterexample. Following the port connection and expression leads to the swap that caused it.

A test with A=B=0 or A=B=1 would pass both versions. Equal input values hide the difference between choosing the correct source and choosing the wrong one. Useful tests distinguish behaviors instead of merely repeating an easy case.

The interactive table enumerates all eight known binary input combinations. The correct version matches eight. The swapped version fails the four combinations where A and B differ. The table exhausts this small binary function, while leaving unknown states, physical timing and injected faults outside that result.

Compilation, simulation and synthesis answer different questions

The download supports two ways to run the example. With Icarus Verilog installed, compile the design and testbench, then execute the result:

iverilog -g2012 -s tb_channel_select_1b -o directed.vvp channel_select_1b.sv tb_channel_select_1b.sv
vvp directed.vvp

The first command reads the files and produces a simulation program. The second executes it. -s chooses the testbench as the top module, and -g2012 selects a language mode. Neither command programs an FPGA or manufactures a chip. [2]

run.sh runs the four directed cases, the eight binary rows and the two-instance comparison. It also checks that the incorrect version fails. The two versions share a module name and must be compiled separately. That failure is expected. A universal PASS from the incorrect version would call the tests into question.

Synthesis reads the hardware module and transforms its function into a circuit representation. synth.ys reads the mux without turning the testbench’s #5, printed messages or test procedure into hardware. This Yosys run retains one generic $mux in its optimized intermediate representation, with no inferred register. It has not mapped the design to a particular chip cell library. [3]

Download the example and reproduce the results

Icarus Verilog 12.0 passed the four directed cases, all eight binary rows and the two-instance comparison. The swapped version produced 4/4 and 4/8 mismatches respectively. Yosys 0.33 produced one one-bit $mux with no storage cells.

Download RTL, testbenches and run instructions (ZIP)

File hashes and tool results
Actual run log
Correct-design VCD waveform

Run environment: Ubuntu 24.04 on WSL, with Bash, Python 3, Icarus Verilog and Yosys. The ZIP includes versions, setup notes and expected results for each step.

What can the panel do now?

The two sensor flags now have an explicit selection rule. A module describes the function, ports identify the connection points, an instance connects it into a design, and assign maintains the input-output relationship. The testbench applies inputs from outside and compares behavior with the original table.

This design selects the current inputs. Changing a sensor flag or select changes the condition driving the output. It has no storage for the preceding result. Holding that result for later use requires a storage element, which the register lesson will introduce.

We have also not established that the sensors are trustworthy or that selection remains correct when signals are disturbed. Functional tests, simulation, synthesis and security analysis support different conclusions. The anti-tampering series will follow the same path from input to stored result to its use, with an explicit fault model added.

Change the requirement

Suppose the panel requirement changes: select=0 must show B, and select=1 must show A. Is the old swapped version still incorrect?

Show the worked answer

Judge it against the new requirement. The previously swapped version now implements the requested mapping, while the original version needs changing. Update the module, expected results and panel labels together. Keeping the old test table would test the wrong requirement.

Names used in this lesson

NameIts role here
RTLRegister-transfer-level hardware description; we begin with its combinational logic.
muxSelects A or B for the output.
module / portThe hardware description and its external signal interface.
instanceA connected use of a module description in a design.
assignMaintains the output’s relationship to its inputs.
testbench / DUTThe program applying and checking inputs, and the circuit being tested.
synthesis / netlistTransformation into a circuit representation, and a record of components and connections.

Check your understanding with five questions

1. With A=1, B=0 and sel=0, what is selected_o?
2. What happens if the two instance declarations change order?
3. What does #5 mean in this testbench?
4. Which input best exposes swapped A and B inputs?
5. What does passing all eight binary cases establish?

Sources and the next lesson

  1. IEEE 1800-2017 SystemVerilog, §10.3 continuous assignments, §11.4.11 conditional operator, §23 modules. Original standard hosted by the MIT course.
  2. Icarus Verilog: Getting Started, compilation and vvp execution.
  3. Yosys: Synthesis starter, the synthesis flow and circuit representations.

The one-bit panel selector is ready. The next lesson expands one-bit signals into multibit data, explains how the same bit pattern can represent different values, and introduces unknown and high-impedance states in four-state logic. For a view of where these skills lead, browse the existing AES-128 RTL article or Anti-Tampering Lesson 1, then return to build their prerequisites step by step.