CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Ternary Operator Safety

MediumVerilog / SystemVerilogBuild

Combinational logic must always assign a value to its outputs under all possible conditions to prevent unintended latches. Hardware engineers often accidentally infer latches by omitting an else branch in an always @(*) block. Using continuous assignments with nested ternary operators (? :) structurally guarantees combinational logic because the syntax strictly requires both a true and a false condition.

A priority data router selects one of three 8-bit data inputs based on their respective valid flags. The router evaluates the valid flags in strict alphabetical priority. If valid_a is asserted, it outputs data_a. If valid_a is deasserted but valid_b is asserted, it outputs data_b. If only valid_c is asserted, it outputs data_c. If no valid flags are asserted, it outputs a fallback default_data value.

This circuit is purely combinational. There is no clock and no reset. Outputs must reflect input changes instantaneously. Priority logic dictates that a higher-priority valid flag completely overrides any lower-priority flags, ignoring their data entirely.

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | valid_a | input | 1 | Valid flag for data input A | | valid_b | input | 1 | Valid flag for data input B | | valid_c | input | 1 | Valid flag for data input C | | data_a | input | 8 | Data input A; highest priority | | data_b | input | 8 | Data input B; medium priority | | data_c | input | 8 | Data input C; lowest priority | | default_data | input | 8 | Fallback data when no valid flags are asserted | | out_data | output | 8 | Selected 8-bit output data |

Constraints

  • The design must be purely combinational with no inferred latches.
  • You must resolve priority in the exact order: A (highest), then B, then C (lowest).
  • You must use a single continuous assignment (assign) with nested ternary operators (? :).
  • Do not use always blocks, if-else statements, or case statements.

Topics

combinationalroutingcontinuous-assignmentternary-operator

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks