SRAM vs DRAM
Memory Arrays · Cache · Verilog
From the 6-transistor SRAM cell to DDR5 DRAM, ROM types, cache hierarchy, and synthesizable Verilog RAM/ROM — everything you need to master digital memory.
SRAM vs DRAM — Core Comparison
SRAM — Static RAM
- 6 transistors per bit (cross-coupled inverters)
- No refresh needed — holds data as long as power on
- Access time: 1–5 ns (cache speed)
- Large area — ~50–150 F² per bit
- Used in: CPU caches, register files, FPGAs, on-chip RAMs
DRAM — Dynamic RAM
- 1 transistor + 1 capacitor per bit
- Capacitor leaks → must refresh every ~64 ms
- Access time: 60–100 ns (with tRCD/tCL)
- Dense — ~6–8 F² per bit, 6× cheaper than SRAM
- Used in: main memory (DDR4, DDR5, LPDDR5)
| Parameter | SRAM | DRAM |
|---|---|---|
| Cell transistors | 6 (+ access transistors) | 1T1C |
| Refresh required | No | Yes (~64 ms) |
| Typical access time | 1–5 ns | 60–100 ns |
| Density | Low (~6× less than DRAM) | High |
| Power | Higher (static leakage) | Lower per bit |
| Volatile | Yes | Yes |
| Primary use | CPU cache, register file | Main memory (DDR) |
Memory Array Organization
A memory with 2^N words × W bits wide has:
| Parameter | Formula | Example: 1K×8 |
|---|---|---|
| Address bits | N = log₂(words) | N = 10 bits |
| Total bits | words × W | 1024 × 8 = 8192 bits |
| Row select (word line) | 2^(N−log₂W) | 128 word lines |
| Column select | log₂(W) | 3 bits → 8 columns |
| Sense amplifiers | W per row | 8 |
Interactive 8×8 RAM Simulator
ROM Types
| Type | Programming | Erasable | Typical Use |
|---|---|---|---|
| Mask ROM | At fabrication | No | High-volume embedded firmware |
| OTP ROM | Once by user (fuse) | No | Security keys, one-time config |
| EPROM | Electrically | UV light (whole chip) | Legacy — replaced by EEPROM |
| EEPROM | Electrically | Electrically (byte) | BIOS, config data, small NVM |
| NAND Flash | Electrically | Block erase | SSD, microSD, USB drives |
| NOR Flash | Electrically | Block erase | Code execution (XIP), MCU flash |
Cache Memory Hierarchy
Verilog — Synchronous RAM & ROM
Synchronous Single-Port RAM
// Synchronous RAM: write on clock edge, read registered
module ram_sp #(
parameter WORDS = 1024,
parameter W = 8,
parameter ADDR = 10 // log2(WORDS)
) (
input logic clk,
input logic [ADDR-1:0] addr,
input logic [W-1:0] wdata,
input logic we,
output logic [W-1:0] rdata
);
logic [W-1:0] mem [0:WORDS-1];
always_ff @(posedge clk) begin
if (we) mem[addr] <= wdata;
rdata <= mem[addr]; // read-first (old data)
end
endmodule
True Dual-Port RAM
// True dual-port: two independent read/write ports
module ram_tdp #(parameter WORDS=1024, W=8, ADDR=10) (
input logic clk,
input logic [ADDR-1:0] addra, addrb,
input logic [W-1:0] wdataa, wdatab,
input logic wea, web,
output logic [W-1:0] rdataa, rdatab
);
logic [W-1:0] mem [0:WORDS-1];
always_ff @(posedge clk) begin
if (wea) mem[addra] <= wdataa;
if (web) mem[addrb] <= wdatab;
rdataa <= mem[addra];
rdatab <= mem[addrb];
end
endmodule
ROM (Lookup Table)
// ROM: initialized with $readmemh or inline case
module rom_lut #(parameter W=8, DEPTH=256, ADDR=8) (
input logic [ADDR-1:0] addr,
output logic [W-1:0] rdata
);
logic [W-1:0] mem [0:DEPTH-1];
initial $readmemh("rom_init.hex", mem); // load from file
assign rdata = mem[addr]; // combinational read
endmodule
// Or inline initialization for small ROMs
always_comb case (addr[3:0])
4'h0: rdata = 8'h3F; // 7-seg '0'
4'h1: rdata = 8'h06; // 7-seg '1'
// ...
default: rdata = 8'h00;
endcase
Frequently Asked Questions
What is the difference between SRAM and DRAM?
SRAM: 6T cell, no refresh, 1–5 ns, large area → caches. DRAM: 1T1C, refresh every 64 ms, 60–100 ns, dense → main memory.
What is synchronous vs asynchronous RAM?
Synchronous RAM is clocked — data output appears one cycle after address. Asynchronous RAM outputs immediately. All modern designs use synchronous for clean timing analysis.
What is a dual-port RAM used for?
Two independent access ports allow simultaneous read+write. Used in register files, FIFOs, video buffers, ping-pong buffers, and any producer/consumer architecture.
What is the difference between NAND and NOR flash?
NAND flash is denser and cheaper — used for mass storage (SSDs). NOR flash supports random byte reads and execute-in-place (XIP) — used for MCU code storage where CPU executes directly from flash.