Problems

3. Priority encoder

EasyWrite the moduleAbout 10 minFree
combinationalencoderpriority

Eight request lines come in on req. Report the number of the highest-numbered line that is active.

idx is the index (0 to 7) of the highest set bit of req. valid is 1 when at least one bit of req is set. When req is all zeros, valid is 0 and idx is 0. There is no clock and no reset.

Ports

Module prio_enc8

PortDirBitsWhat it is
reqin8Request lines; bit 7 has the highest priority.
idxout3Index of the highest set bit, or 0 when none is set.
validout11 when any request is set.

Example

req = 0001_0100: lines 2 and 4 are active, so idx = 4 and valid = 1. req = 0000_0000 gives idx = 0, valid = 0.

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Verilogprio_enc8.v
14px
Loading the editor…

Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.

Priority encoder: Verilog interview question | breadboardhub