3. Priority encoder
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
| Port | Dir | Bits | What it is |
|---|---|---|---|
req | in | 8 | Request lines; bit 7 has the highest priority. |
idx | out | 3 | Index of the highest set bit, or 0 when none is set. |
valid | out | 1 | 1 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.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
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.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.