Ternary Operator Safety
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
alwaysblocks,if-elsestatements, orcasestatements.
Topics
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.
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.