Part of Curriculum: Verilog Fundamentals (Module 4: 2:1 Multiplexers & Conditional Operators)
View Full Roadmap →
Level 1 Easy ★ Flagship #5 10 pts ✓ Solved

2:1 Multiplexer — Conditional Selection

Combinational Logic · combinational, logic-gates, easy, multiplexers-&-decoders

Design a 1-bit 2-to-1 multiplexer that selects input a when sel=0, and input b when sel=1.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
abseloutMULTIPLEXERCONDITIONAL SELECT
⚡ Timing & Synthesizability Constraints

Timing Contract: Combinational path: select-to-out ($t_{sel \to out}$) and data-to-out ($t_{data \to out}$).

RTL Constraints: Pure combinational RTL; no latches.

Objective: Master conditional selection using the ternary operator `? :` and multiplexer datapath concepts.

Prerequisites: Boolean selection, conditional expressions.
NameDirWidthDescription
ainput1Data input 0 (selected when sel=0)
binput1Data input 1 (selected when sel=1)
selinput1Control selection bit
outoutput1Selected data output
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
You can use the conditional ternary operator `? :`.
Hint 2: Implementation Architecture & Approach
The syntax is `condition ? true_value : false_value`.
Hint 3: Edge Cases, Timing & Verilog Syntax
Write `assign out = sel ? b : a;`.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module(
  input   a,
  input   b,
  input   sel,
  output  out
);
  assign out = sel ? b : a;
endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 1 · Combinational Logic

What You Will Learn

By solving 2:1 Multiplexer — Conditional Selection, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Design a 1-bit 2-to-1 multiplexer that selects input a when sel=0, and input b when sel=1.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Master conditional selection using the ternary operator `? :` and multiplexer datapath concepts.

Prerequisites: Boolean selection, conditional expressions.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

NameDirWidthDescription
ainput1Data input 0 (selected when sel=0)
binput1Data input 1 (selected when sel=1)
selinput1Control selection bit
outoutput1Selected data output

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Combinational path: select-to-out ($t_{sel \to out}$) and data-to-out ($t_{data \to out}$).

Synthesis Constraints: Pure combinational RTL; no latches.

Architectural Deep Dive & Implementation Walkthrough

A 2:1 multiplexer routes one of two inputs to the output based on `sel`. Boolean equation: $out = (\sim sel \& a) | (sel \& b)$. In hardware description, using `sel ? b : a` is synthesizable directly into dedicated multiplexer primitives (such as FPGA MUXF7 or standard cell MUX2X).

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Inverting order: writing `sel ? a : b` selects `a` when `sel=1`, which reverses the specification.', 'Using an unclocked `always` block without covering all inputs, creating an unwanted latch.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

Modern FPGAs feature dedicated multiplexer resources adjacent to Look-Up Tables (LUTs) allowing wide multiplexing without routing penalties.

Starter RTL Code

module top_module(
  input   a,
  input   b,
  input   sel,
  output  out
);

  // Select a when sel=0, b when sel=1

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input   a,
  input   b,
  input   sel,
  output  out
);
  assign out = sel ? b : a;
endmodule
Advertisement

Related RTL Problems in Level 1

Frequently Asked Questions

What does 2:1 Multiplexer — Conditional Selection require?

Design a 1-bit 2-to-1 multiplexer that selects input a when sel=0, and input b when sel=1. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: combinational, logic-gates, easy, multiplexers-&-decoders. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of 2:1 Multiplexer — Conditional Selection to assess real-world synthesizability and race-condition awareness.

Advertisement