Decode a 12-bit address map with ranges, a wildcard pattern, a list of single addresses and one region that overlaps two others.
Hardware context: An idle timer for a four-lane link, and a 12-bit address decoder with six regions. Write the region decoder from its address map.
A small system has six regions on a 12-bit address bus. Two are plain ranges. One is a short range. One repeats its four registers across a whole page, so its rule is a bit pattern. One is three single addresses. The last, PATCH, lies across the border of ROM and RAM and must win over both.
This is an Implement problem: write the body of region_dec. The fixture applies eight addresses per case, one per nanosecond, and records region and hit after each. An address in no region is a miss: region 0 and hit 0.
Brief: combinational, no clock and no reset. The map is in the specification. The inside operator fits every row of it; any combinational form is allowed. This problem runs on Verilator. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
addrs | 96 | input of each check |
Full specification
module region_dec (
input logic [11:0] addr,
output logic [2:0] region, // 0 when no region holds addr
output logic hit // 1 when a region holds addr
);
// your design
endmodule
| region | Name | Addresses (hex) |
|---|---|---|
| 1 | ROM | 000 to 3ff |
| 2 | RAM | 400 to 5ff |
| 3 | UART | 800 to 80f |
| 4 | TIMER | every address 9xy where the two bits above the lowest two bits are 00: binary 1001 ???? 00?? |
| 5 | PATCH | 3f8 to 407; wins over ROM and RAM |
| 6 | ID | ff0, ff4 and ffc only |
| 0 | miss | every other address; hit is 0 |
The result lists region and hit for each of the eight addresses of a case.
Examples
Example 1
ROM, PATCH and RAM- Input
addr (hex): 000 3f7 3f8 3ff 400 407 408 5ff
- Output
region_0 = ROM (1), hit_0 = yes, region_1 = ROM (1), hit_1 = yes, region_2 = PATCH (5), hit_2 = yes, region_3 = PATCH (5), hit_3 = yes, region_4 = PATCH (5), hit_4 = yes, region_5 = PATCH (5), hit_5 = yes, region_6 = RAM (2), hit_6 = yes, region_7 = RAM (2), hit_7 = yes
3f7 is the last plain ROM address. 3f8 to 407 belong to PATCH, on both sides of the border. 408 is plain RAM again.
Example 2
The Hole After RAM, and the UART- Input
addr (hex): 600 7ff 800 80f 810 8ff 80e 601
- Output
region_0 = miss (0), hit_0 = no, region_1 = miss (0), hit_1 = no, region_2 = UART (3), hit_2 = yes, region_3 = UART (3), hit_3 = yes, region_4 = miss (0), hit_4 = no, region_5 = miss (0), hit_5 = no, region_6 = UART (3), hit_6 = yes, region_7 = miss (0), hit_7 = no
600 to 7ff is in no region. The UART holds exactly sixteen addresses, 800 to 80f; 810 is a miss.
Example 3
The TIMER Pattern- Input
addr (hex): 900 903 904 9f3 9a2 9a8 90c a00
- Output
region_0 = TIMER (4), hit_0 = yes, region_1 = TIMER (4), hit_1 = yes, region_2 = miss (0), hit_2 = no, region_3 = TIMER (4), hit_3 = yes, region_4 = TIMER (4), hit_4 = yes, region_5 = miss (0), hit_5 = no, region_6 = miss (0), hit_6 = no, region_7 = miss (0), hit_7 = no
900 and 903 match. 904 does not: bit 2 is 1. 9f3 and 9a2 match, because the middle four bits are free.
Constraints and Contract
- Inputs are known 0/1 values. Each address is held for one nanosecond and the outputs are sampled at its end.
- Keep the module name and the ports. No latch: region and hit have a value for every address.
Hints
Hint 1
Give region a default of 0 at the top of the block. Every address that matches nothing is then a miss, with no extra code.
Hint 2
Both ends of a range belong to it: [12'h800:12'h80f] includes 80f. For TIMER, write the pattern in binary and count which bits are fixed.
Hint 3
PATCH shares addresses with ROM and with RAM. In a chain of if and else if, the first true test wins. Where must the PATCH test stand?
What the grader checks: Six directed and twelve seeded cases apply eight addresses each, on and around every border of the map. An independent model checks every result. Passing shows the decoder is right on those addresses, not on all 4096; the synthesis check adds the latch count.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
18 checks on Verilator + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone