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

If Else Priority Encoder

EasyVerilog / SystemVerilogBuild

Microcontrollers receive multiple hardware interrupt requests simultaneously and must decide which to service first. An interrupt controller resolves these simultaneous requests by assigning a strict priority hierarchy to each source. When synthesized, cascaded conditional statements naturally form a priority routing structure in hardware.

The module evaluates an 8-bit interrupt request vector and outputs the index of the highest-priority active interrupt. Interrupt 0 (the least significant bit) has the highest priority, and interrupt 7 (the most significant bit) has the lowest priority. If any interrupt is active, a valid flag is asserted.

This module is purely combinational. There is no clock or reset.

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | irq | input | 8 | Interrupt request vector; each bit represents an independent interrupt source | | irq_id | output | 3 | Index of the highest priority active interrupt; defaults to 0 if none are active | | valid | output | 1 | Asserted (1) if at least one interrupt is active, 0 otherwise |

Constraints

  • The circuit must be purely combinational with no latches
  • irq[0] possesses the highest priority, while irq[7] possesses the lowest priority
  • When irq is all zeros, irq_id must explicitly output 0 and valid must output 0

Topics

CombinationalPriority LogicSynthesis Intuition

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