Codiode

Ternary Operator Mux

EasyVerilog / SystemVerilogBuildFree25 solved

A 2-to-1 mux is the smallest routing decision in hardware, and sel ? a : b is the most direct way to write it.

This module routes one of two 8-bit input data buses to an 8-bit output bus based on the state of a single select bit. When the select bit is high, the first input bus is routed to the output. When the select bit is low, the second input bus is routed to the output.

This is a purely combinational circuit. There is no clock and no reset. The output must reflect the selected input immediately without any registered delay.

Signal Direction Width Description
a input 8 Data input selected when sel is 1
b input 8 Data input selected when sel is 0
sel input 1 Select signal; determines which input drives out
out output 8 Selected data output

Constraints

  • The module must be purely combinational.
  • Output out must strictly follow a when sel is 1, and b when sel is 0.
  • The design must not use clocks, resets, or flip-flops.
  • The data buses are exactly 8 bits wide.

Topics

CombinationalMultiplexerData RoutingTernary Operator

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

Free to solve. A Codiode account keeps your progress.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Verilog Syntax and Language Basics

Problem 14 of 25 in the Verilog Syntax and Language Basics track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.