RTL Design #57 · 2026-11-19 · Associative table · Medium · about 30 min
Build a 4-entry translation table
Build tlb4, a tiny translation table that maps an 8-bit virtual page number (vpn) to a 6-bit physical page number (ppn). It holds 4 entries; each is either valid or empty, and holds a vpn and a ppn.
- Lookup is combinational.
hitis 1 when a valid entry holdslvpn, and thenlppnis that entry'sppn. With no hit,hitis 0 andlppnis 0. A fill only shows in a lookup after its clock edge. - Fill: on a rising edge with
fill= 1, the pair (fvpn,fppn) is stored.- If a valid entry already holds
fvpn, only that entry'sppnis replaced. - Otherwise the pair goes into the entry a round-robin pointer selects, which then moves to the next entry (0, 1, 2, 3, 0, ...). The pointer is used even when that entry is empty, and a fill that updates a matching entry leaves it alone.
- If a valid entry already holds
- Flush: on a rising edge with
flush= 1, every entry becomes empty and the pointer returns to entry 0. Iffillis also 1 in that clock, the fill is ignored. - Reset: synchronous,
rst_nlow: same as a flush (and it also overridesfill).
Example (after reset): fill 0x10 → 0x01, 0x20 → 0x02, 0x30 → 0x03, 0x40 → 0x04, 0x50 → 0x05. The fifth fill takes entry 0 again, so a lookup of 0x10 misses and 0x50 hits with lppn 0x05; 0x20, 0x30 and 0x40 still hit.
Write and run your answer in the browser. The hidden tests check it, and it’s free.