Lesson 37 of 48 intermediate

Memory Interfacing with RAM and ROM

Connecting the CPU to Its Storage

Open interactive version (quiz + challenge)

Real-world analogy

Imagine a post office with numbered PO boxes. The CPU is the mail carrier who knows every box number (address). ROM boxes are locked glass cases — you can read the mail inside but never change it. RAM boxes have doors you can open to read or replace mail. Address decoding is like the sorting machine that routes each letter to the correct wing of the post office.

What is it?

Memory interfacing is the process of connecting RAM and ROM chips to the 8086 CPU so it can read instructions from ROM and read/write data in RAM. It involves address decoding (using logic gates or decoder ICs like 74LS138) to generate chip select signals, mapping memory chips to specific address ranges, and handling the 16-bit data bus with even/odd bank organization.

Real-world relevance

Every computer, phone, and embedded device uses memory interfacing. Your PC's BIOS is stored in ROM mapped at the top of address space — just like the 8086. RAM modules in your laptop use far more complex decoding, but the principle of chip selection and address mapping is identical to what we learn here.

Key points

Code example

; =============================================
; Memory Interface: 8KB ROM + 8KB RAM for 8086
; =============================================
;
; ROM (2764): mapped at FE000h - FFFFFh
; RAM (6264): mapped at 00000h - 01FFFh
;
; --- ROM Address Decoding ---
; A19=1, A18=1, A17=1, A16=1, A15=1, A14=1, A13=1
; CS_ROM = NAND(A19,A18,A17,A16,A15,A14,A13)
;
; ROM connections:
;   A0-A12  → ROM address pins
;   D0-D7   → ROM data pins
;   RD      → ROM OE (Output Enable)
;   CS_ROM  → ROM CE (Chip Enable)
;
; --- RAM Address Decoding ---
; A19=0, A18=0, A17=0, A16=0, A15=0, A14=0, A13=0
; CS_RAM = NOR(A19,A18,A17,A16,A15,A14,A13)
;
; RAM connections:
;   A0-A12  → RAM address pins
;   D0-D7   → RAM data pins
;   RD      → RAM OE
;   WR      → RAM WE (Write Enable)
;   CS_RAM  → RAM CE
;
; Verification:
;   MOV AL, [0000h]  ; reads from RAM ✓
;   JMP FFFF0h       ; executes from ROM ✓

Line-by-line walkthrough

  1. 1. Title comment for our memory interface design
  2. 2. Describing the system: 8KB ROM and 8KB RAM connected to 8086
  3. 3. Blank separator
  4. 4. ROM chip 2764 will live at addresses FE000h through FFFFFh (top 8KB)
  5. 5. RAM chip 6264 will live at addresses 00000h through 01FFFh (bottom 8KB)
  6. 6. Blank separator
  7. 7. Starting ROM address decoding section
  8. 8. For FE000h-FFFFFh, address bits A19 through A13 must all be 1
  9. 9. NAND gate: output goes LOW (active) only when all inputs are HIGH
  10. 10. Blank separator
  11. 11. ROM wiring: CPU address lines A0-A12 connect to ROM address pins
  12. 12. ROM data pins connect to CPU data bus D0-D7
  13. 13. CPU RD signal connects to ROM Output Enable — read activates data output
  14. 14. The decoded chip select connects to ROM Chip Enable pin
  15. 15. Blank separator
  16. 16. Starting RAM address decoding section
  17. 17. For 00000h-01FFFh, address bits A19 through A13 must all be 0
  18. 18. NOR gate: output goes HIGH inverted to LOW (active) when all inputs are 0
  19. 19. Blank separator
  20. 20. RAM wiring: same A0-A12 to RAM address pins
  21. 21. RAM data pins connect to D0-D7
  22. 22. RD signal to RAM OE for read operations
  23. 23. WR signal to RAM WE for write operations — RAM is read/write unlike ROM
  24. 24. Decoded chip select to RAM CE pin
  25. 25. Blank separator
  26. 26. Verification section
  27. 27. Reading from address 0000h hits RAM — confirmed by decoding
  28. 28. Reset jump to FFFF0h executes from ROM — confirmed by decoding

Spot the bug

; Memory decoding for ROM at F0000-FFFFF (64KB)
; Using 74LS138 decoder
;
; C=A19, B=A18, A=A17
; G1=Vcc, G2A=A16, G2B=GND
;
; ROM connected to output Y7
; Y7 active when CBA = 111 and G2A = 0
;
; So ROM is selected when:
;   A19=1, A18=1, A17=1, A16=0
;   Address range: E0000h - EFFFFh
Need a hint?
Check what address A19=1, A18=1, A17=1, A16=0 actually represents. Does it match F0000-FFFFF?
Show answer
The decoding selects E0000h-EFFFFh, NOT F0000h-FFFFFh. When A16=0 (required for G2A active LOW), the range starts at E0000h. To select F0000h-FFFFFh, G2A should be connected to NOT(A16), so G2A=0 when A16=1. Alternatively, use A16 through an inverter before connecting to G2A.

Explain like I'm 5

Think of the CPU as a librarian in a huge library. The library has two sections: a 'read-only' section (ROM) where books are behind glass — you can look but not change them — and a 'read-write' section (RAM) where you can borrow, return, and even scribble notes. Address decoding is like the sign at each aisle telling the librarian which section and shelf to go to based on the book number.

Fun fact

The original IBM PC used a 74LS138 decoder to divide its 1MB address space into 8 blocks of 128KB each. This single cheap chip was the traffic controller for the entire memory system — routing every memory access to the correct chip. The 74LS138 is still manufactured today and costs about 50 cents.

Hands-on challenge

Design a memory map for an 8086 system with 32KB ROM at the top of memory and 64KB RAM at the bottom. Draw the address ranges, determine which address lines to decode, and specify the logic (gates or decoder) needed for chip select generation. Verify that the reset vector falls within your ROM range.

More resources

Open interactive version (quiz + challenge) ← Back to course: Microprocessor A–Z