easy 10 pts Solved

4-Entry Content-Addressable Memory (CAM)

Search all 4 stored entries in parallel for a key — the associative-lookup structure behind TLBs and packet-classification hardware.

Verilog problems / Sequential Design

What you must build

Search all 4 stored entries in parallel for a key — the associative-lookup structure behind TLBs and packet-classification hardware.

Engineers use “4-Entry Content-Addressable Memory (CAM)” as a building block in sequential design. Interviewers ask for the same ports and the same corner cases this judge covers. Completing it in the browser is the same skill as writing synthesizable RTL at work, minus the EDA license.

Concept: A CAM compares the search key against every stored entry simultaneously, producing a one-hot(ish) match vector; found is simply whether any entry matched: found = |match. Using & (AND-reduce) instead of | (OR-reduce) is a classic reduction-operator mix-up — it silently redefines "found" to mean "every single entry matches the key," which is only ever true in the degenerate case where all 4 entries happen to hold the same value, making the CAM report "not found" for essentially every real search.

Port contract

The judge instantiates exactly these ports. Extra ports or a different module name fail to elaborate.

NameDirWidthDescription
entry0input4Stored entry 0
entry1input4Stored entry 1
entry2input4Stored entry 2
entry3input4Stored entry 3
search_keyinput4Key to search for
matchoutput4match[i]=1 if entry i equals search_key
foundoutput11 if any entry matched

How to approach this kata

This is an introductory kata. Prefer a clear continuous assignment or a small combinational always block. Name the module top_module and keep the port list identical to the table — the hidden testbench instantiates that name.

Hidden tests instantiate top_module, drive the ports, and compare every sample against a golden model. They do not grade coding style. They do grade X/Z, off-by-one counters, and ignoring enables. Sign in only when you want the run saved on the leaderboard — the specification below is public.

Starter shape

Copy this skeleton into the editor (or press Reset starter). Fill the body; do not rename the module.

module top_module(
  input  [3:0] entry0,
  input  [3:0] entry1,
  input  [3:0] entry2,
  input  [3:0] entry3,
  input  [3:0] search_key,
  output [3:0] match,
  output found
);

  // Your code here — match[i] = (entry_i == search_key) for each of the 4 entries; found = |match.

Why this shows up in interviews

4-Entry Content-Addressable Memory (CAM) sits under Sequential Design (combinational, memory). Concept: A CAM compares the search key against every stored entry simultaneously, producing a one-hot(ish) match vector; found is simply whether any entry matched: found = |match . Using & (AND-reduce) instead of | (OR-reduce) is a classic reduction-operator mix-up — it silently redefines "found" to mean "every single entry matches the key," which is only ever true in the degenerate case where all 4 entries happen to hold the same value, making the CAM report "not found" for essentially every real search.

A passing solution is synthesizable intent: no delays in the DUT, no initial blocks inside top_module, and no reference to testbench tasks. Use blocking assignments only in combinational always blocks; use non-blocking for registers clocked by clk.

Related problems

  • D Flip-Flop with Asynchronous Reset — Standard D flip-flop with an active-low asynchronous reset. Reset clears q immediately, without waiting for a clock edge.
  • 4-Bit Shift Register (SIPO) — Serial-in, parallel-out shift register. Each clock, shift left and load sin into the LSB. Sync active-high reset clears q.
  • JK Flip-Flop — The flip-flop with no forbidden state: j=k=1 toggles instead of racing. Classic building block for counters.
  • 4-Bit Up/Down Counter — A synchronous counter that increments or decrements each clock edge depending on a direction input, with a synchronous reset.

FAQ

What does this problem require?

What does the 4-Entry Content-Addressable Memory (CAM) problem ask for? Search all 4 stored entries in parallel for a key — the associative-lookup structure behind TLBs and packet-classification hardware. Implement it as Verilog module top_module with the listed ports.

Combinational or sequential?

Is 4-Entry Content-Addressable Memory (CAM) combinational or sequential? Tags: combinational, memory. Follow the clock/reset ports if they appear in the table; if there is no clock, use continuous assignment or combinational always @(*).

How does the auto-grader work?

How is 4-Entry Content-Addressable Memory (CAM) graded? A hidden SystemVerilog/Verilog testbench in the EcrioniX judge simulates your module in the browser. You pass when every directed vector matches, including the waveform contract shown on this page.

Write a module named top_module matching the ports below exactly.
Expected waveform
Your solution
Judge output
// Output appears after you run tests.