RTL Design #22 · 2026-10-15 · CAMs · Easy · about 10 min
A CAM that finds keys nobody stored
cam4 is a four-entry content-addressable memory: you give it a key and it tells you which entry holds that key.
- Write. On a rising edge with
wr_en= 1, entrywr_idxis replaced. Withwr_valid= 1 it now holdswr_key; withwr_valid= 0 it's empty, whateverwr_keyis. - Lookup. Combinationally,
hitis 1 when some entry holdskey, andhit_idxis the lowest-numbered entry that does. With no match,hitandhit_idxare both 0. - Reset empties every entry.
A key can be any 8-bit value. The current design sometimes reports a hit for a key that isn't stored in any entry. Fix cam.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.