HDL & Verification
reg [7:0] mem [0:255];
always @(posedge clk) begin
if (we) mem[addr] <= din;
dout <= mem[addr];
endWhen the code above is synthesized for an FPGA, how is it generally implemented?
- AIt cannot be synthesized and causes an error
- BIt becomes 256 independent adders
- CIt is inferred as an 8-bit × 256-word memory and mapped to the FPGA's built-in block RAM
Show answer and explanation
Answer: C. It is inferred as an 8-bit × 256-word memory and mapped to the FPGA's built-in block RAM
When a reg array is written and read synchronously with the clock in a standard pattern, FPGA synthesis tools recognize (infer) it as memory and map it to the built-in block RAM. Making the read synchronous too is the key to matching block RAM; an asynchronous read may instead be built from many flip-flops or a different kind of memory. In ASIC design, SRAM and other memories made with a memory compiler are usually instantiated explicitly.
- A. A reg array can be synthesized as memory.
- B. No addition is involved.
- C. Correct. Written in a standard pattern, it is recognized as memory.