HDL & Verification

reg [7:0] mem [0:255];
always @(posedge clk) begin
    if (we) mem[addr] <= din;
    dout <= mem[addr];
end

When the code above is synthesized for an FPGA, how is it generally implemented?

  1. AIt cannot be synthesized and causes an error
  2. BIt becomes 256 independent adders
  3. 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.

Related calculators

Books on HDL & Verification Ad

As an Amazon Associate I earn from qualifying purchases.

More HDL & Verification questions

  1. In combinational logic, how does a long if/else-if chain compare with a case statement whose conditions are mutually exclusive?
  2. What is the difference between Verilog's equality operators "==" and "==="?
  3. The code above was written intending an accumulator that keeps adding the input in. Which pair correctly states the problem with this code and how to fix it?
  4. What is a major difference between a description written in an HDL such as Verilog and a software program in a language such as C?
  5. What is the purpose of a module in Verilog?

Comparisons in this topic