Design a synchronous single-port RAM with 16 words of 4 bits. On each rising clock edge: if we is 1, din is written to the word at addr; and dout is loaded with the word at addr as it was before this edge (read-before-write, so writing and reading the same address returns the old contents). There is no reset.
Inputs: clk, we, addr (4 bits), din (4 bits).
Output: dout (4 bits).
The testbench first writes all sixteen words, then mixes reads and writes for 72 cycles in total, checking dout against a reference memory.
Contributed by Indicore