Side-by-side comparison
| Parameter | ROM | RAM |
|---|---|---|
| Volatility | Non-volatile — retains data without power | Volatile — loses data on power-off (standard RAM) |
| Write Operation | Read-only (mask ROM) or limited writes (EPROM/Flash) | Read and write freely at runtime |
| Access Time (typical) | 45–150 ns (parallel NOR Flash) | <10 ns (SRAM), ~60 ns (DRAM) |
| Typical IC | AT28C256 (32Kx8 EEPROM), W25Q128 (SPI Flash) | CY7C1021 (SRAM), DDR4 DIMM (DRAM) |
| Use in 8051 | External code memory (EA=0) | External data memory (MOVX instruction) |
| Endurance | Flash: ~100,000 write cycles; Mask ROM: infinite reads | SRAM: infinite; DRAM: infinite |
| Cost | Higher per bit for Flash; mask ROM cheap at volume | Lower per bit for DRAM |
| Power during Read | Low (NOR Flash: ~15 mA active) | Low for SRAM; moderate for DRAM with refresh |
| Data at Power-On | Valid — firmware ready to execute | Indeterminate — must be initialised |
| In Modern MCU | Internal Flash (e.g., STM32F103: 128 KB Flash) | Internal SRAM (STM32F103: 20 KB SRAM) |
Key differences
ROM retains data without power — the STM32F103 has 128 KB of internal Flash that holds firmware across resets. RAM loses all data on power-off — that same chip has 20 KB SRAM for stack, heap, and variables. The critical difference in exam questions is write capability: standard mask ROM cannot be written after manufacture; Flash (a ROM variant) allows up to 100,000 erase-write cycles. RAM supports unlimited random reads and writes at runtime, making it essential for any data that changes during program execution. Confusing them leads to incorrect memory map assignments.
When to use ROM
Use ROM (internal Flash on STM32 or AT28C256 parallel EEPROM) to store firmware, calibration constants, or lookup tables that must survive power cycling and are rarely or never changed during field operation.
When to use RAM
Use RAM (SRAM in a microcontroller or external CY7C1021) for all runtime variables, stack space, and data buffers that are written and read repeatedly during program execution.
Recommendation
For exam memory map questions, assign ROM (Flash) to the code segment starting at 0x0000 and RAM to the data segment. Choose internal Flash for firmware and internal SRAM for variables — this matches the STM32 and 8051 memory model directly.
Exam tip: Examiners ask you to draw the 8051 memory map with internal ROM (0000H–0FFFH) and internal RAM (00H–7FH) separately — note that EA pin controls whether internal or external ROM is accessed first.
Interview tip: Interviewers at embedded companies ask what happens if you write to a ROM address in C — explain that it either causes a hard fault (Flash without erase) or is silently ignored, and that const variables are placed in Flash by the linker.