Part of Curriculum: Verilog Fundamentals (Module 5: 4:1 Multiplexers & Multi-Input Routing)
View Full Roadmap →
Level 1 Easy ★ Flagship #6 15 pts ✓ Solved

4:1 Multiplexer — Multi-Input Selection

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

Design a 4-to-1 multiplexer that selects between 4 single-bit inputs in[3:0] using a 2-bit select code sel[1:0].

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
in[3:0]sel[1:0]outMULTIPLEXERCONDITIONAL SELECT
⚡ Timing & Synthesizability Constraints

Timing Contract: Combinational path: propagation delay from any data bit or select bit to output.

RTL Constraints: Synthesizable combinational design.

Objective: Understand multi-way vector indexing, `case` statements vs nested ternary operators in combinational logic.

Prerequisites: 2-bit vectors, multiplexing, binary encoding.
NameDirWidthDescription
ininput44-bit data bus {in[3], in[2], in[1], in[0]}
selinput22-bit selection input
outoutput1Selected single-bit output
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
In Verilog, bit vector indexing with a variable index `in[sel]` automatically synthesizes into a multiplexer!
Hint 2: Implementation Architecture & Approach
Alternatively, nested ternary operators `sel == 2'b00 ? in[0] : ...` or a `case` statement in an `always @(*)` block can be used.
Hint 3: Edge Cases, Timing & Verilog Syntax
The most concise and elegant Verilog is `assign out = in[sel];`.
🔒 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   [3:0] in,
  input   [1:0] sel,
  output        out
);
  assign out = in[sel];
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 4:1 Multiplexer — Multi-Input 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 4-to-1 multiplexer that selects between 4 single-bit inputs in[3:0] using a 2-bit select code sel[1:0].

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: Understand multi-way vector indexing, `case` statements vs nested ternary operators in combinational logic.

Prerequisites: 2-bit vectors, multiplexing, binary encoding.

Port List & Interface Timing

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

NameDirWidthDescription
ininput44-bit data bus {in[3], in[2], in[1], in[0]}
selinput22-bit selection input
outoutput1Selected single-bit output

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Combinational path: propagation delay from any data bit or select bit to output.

Synthesis Constraints: Synthesizable combinational design.

Architectural Deep Dive & Implementation Walkthrough

Because `sel` is a 2-bit variable, evaluating `in[sel]` dynamically selects the bit at index $0, 1, 2,$ or $3$. Logic synthesis tools infer a balanced 4:1 multiplexer tree (or two levels of 2:1 MUXes).

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Hardcoding fixed indices instead of using the `sel` variable.', 'Writing a procedural `case` without a `default` branch, inferring unintended latches.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

A 4:1 multiplexer fits inside a single 6-input LUT (LUT6) in modern AMD/Xilinx 7-series or UltraScale FPGAs (4 data inputs + 2 select inputs = 6 inputs, 1 output).

Starter RTL Code

module top_module(
  input   [3:0] in,
  input   [1:0] sel,
  output        out
);

  // Select in[0] for sel=00, in[1] for sel=01, in[2] for sel=10, in[3] for sel=11

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input   [3:0] in,
  input   [1:0] sel,
  output        out
);
  assign out = in[sel];
endmodule
Advertisement

Related RTL Problems in Level 1

Frequently Asked Questions

What does 4:1 Multiplexer — Multi-Input Selection require?

Design a 4-to-1 multiplexer that selects between 4 single-bit inputs in[3:0] using a 2-bit select code sel[1:0]. 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 4:1 Multiplexer — Multi-Input Selection to assess real-world synthesizability and race-condition awareness.

Advertisement