Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
    • SRAM and ROM
      • Inference Starts from Coding Style
      • Single-Port Synchronous RAM Template
      • Read-First vs Write-First
      • Dual-Port RAM Patterns
      • True Dual-Port RAM and Collisions
      • ROM Inference
    • Register Files
    • Valid/Ready Handshake
    • AXI-Lite
    • AXI-Stream
    • Bus Integration
    • Synchronous FIFO
    • Register-Map and CSR RTL
    • Memory Reliability
    • Peripheral RTL Integration
    • Full AXI4: RTL Roadmap
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Memory & Buses
  1. Topics
  2. RTL Design
  3. Memory & Buses
  4. SRAM and ROM

Part 7 · Memory & Buses · Intermediate

SRAM and ROM

Coding styles that infer SRAM and ROM blocks, with read-during-write and dual-port rules.

  • 6topics
  • 6lessons

Topics in this section

  1. 1Inference Starts from Coding Style1 lesson
  2. 2Single-Port Synchronous RAM Template1 lesson
  3. 3Read-First vs Write-First1 lesson
  4. 4Dual-Port RAM Patterns1 lesson
  5. 5True Dual-Port RAM and Collisions1 lesson
  6. 6ROM Inference1 lesson
On this page

    Conventional FPGA block RAM and selected synchronous SRAM macros expect an array, a clocked write, and a synchronous read with no array reset. SRAM as a category also includes asynchronous-read resources. Density and speed relative to flip-flops depend on depth, width, ports, latency and target; compare mapped implementations before choosing.

    The same 64-word RAM two ways: an array with a clocked read register fits one RAM block; with an array reset it falls back to flip-flops and a read mux

    Read the two halves as two netlists for the same RTL behaviour. The left one is what the coding rules in this topic aim for; the right one is what the synthesiser builds when the code breaks a rule.

    • Left: the array and its read register sit inside one block. That only works if the read is clocked and the array is never reset.

    • Right: every word becomes its own register and the read becomes a wide mux. An array reset (ram_reset in the next lesson) forces this, because a RAM block cannot clear all its words in one cycle.

    Lessons in this topic

    6 lessons, about 25 min

    1. 1Inference Starts from Coding StyleYou can write a RAM that infers a block RAM, and name what breaks inference: an asynchronous read, an array reset or heavy address logic.4 min
    2. 2Single-Port Synchronous RAM TemplateYou can build a single-port synchronous RAM with a registered read, and predict dout for each cycle around a same-address write.4 min
    3. 3Read-First vs Write-FirstYou can compare read-first, write-first and no-change, and pick the mode a design needs before checking that the target supports it.4 min
    4. 4Dual-Port RAM PatternsYou can choose between simple and true dual-port RAM, and explain why a same-address access across two clocks must be prevented by design.4 min
    5. 5True Dual-Port RAM and CollisionsYou can list the ways to handle a write-write collision and say what each costs in the write-enable path.5 min
    6. 6ROM InferenceYou can write a ROM in array style and in case style, and choose between them by table size and read timing.4 min

    Interview

    “How do you make sure a RAM is inferred as a block RAM?” Synchronous read, no reset on the array, standard write enable, read-during-write behaviour that the block supports, and checking the synthesis report for the memory it built.

    Check yourself Why does a RAM with a combinational (asynchronous) read usually not map to a conventional FPGA block RAM?

    That resource requires a clocked read interface. An asynchronous-read contract instead needs a compatible resource, such as supported distributed RAM or flip-flops; other SRAM technologies may provide asynchronous reads.

    Revision sheet

    The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.

    Inference Starts from Coding Style

    • Write synchronously with an enable, read into a register, and never reset the array.

    • Reset the control logic around the memory. To clear contents, run a short state machine after reset.

    • A generic memory cell in the Yosys output is not proof of a mapped block RAM. Check the target-specific report.

    Rule of thumb: read the synthesis report and look for a RAM of the expected size, not thousands of flops.

    Single-Port Synchronous RAM Template

    • Data appears one cycle after the address, so a valid bit must travel with the request.

    • A write to the address being read shows the old word on dout (read-first); the new word appears on a later read.

    • A clocked consumer sees the result one edge after dout updates.

    Rule of thumb: wrap the RAM so the rest of the design never assumes its latency.

    Read-First vs Write-First

    • The modes differ in one slot only: a read in the same cycle, at the same address, as the write.

    • Any mode returns the new data for a read issued after the write.

    • The mode is part of the RAM's contract. An unsupported mode costs a bypass mux and comparator.

    Rule of thumb: choose the mode the design needs first, then check the target provides it natively.

    Dual-Port RAM Patterns

    • Use a simple dual-port RAM when one side only writes and the other only reads: it is smaller, faster and has fewer collision cases.

    • Across two clocks, a read of an address being written is undefined. The async FIFO avoids it by keeping the pointers apart.

    • Wide RAMs and unusual port-width ratios can need several blocks or a vendor template.

    True Dual-Port RAM and Collisions

    • A same-cycle write to one address is undefined in hardware and not portable.

    • Prevent it by arbitration or address partitioning, or define it in a wrapper with a priority port and a collision flag.

    • A collision-safe wrapper needs one clock for both ports, and the address comparator can become the critical path.

    Rule of thumb: never leave a collision undefined: prevent it, or define the winner and raise a flag.

    ROM Inference

    • An array with a synchronous read maps to a block ROM. A combinational read becomes logic.

    • A tiny table, such as four entries, is cheaper as a case than as a memory block with its overhead.

    • On an FPGA the initial contents go into the bitstream. On an ASIC the ROM macro is a separate cell.

    Rule of thumb: generate the table from a function or a file, because hand-typed numbers rot.

    Practise it

    • Mini project: a two-master bus with decoder, default slave and timeout

    • Practice question: Asynchronous read memory design in SystemVerilog

    • Code lab: SRAM model 16x8

    • Practice question: Single-port RAM with write-first behaviour

    • Practice question: Dual-port RAM with read-after-write handling

    • Code lab: Simple dual-port RAM

    • Interview: run a mock interview on this topic

    PreviousNext: Inference Starts from Coding Style

    Up next

    Up nextInference Starts from Coding Style

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Register Files
    • Valid/Ready Handshake
    • AXI-Lite