Loading lessons...
Memory Unit: RAM Organisation, Decoding & Expansion
Memory Unit: RAM Organisation, Decoding & Expansion
A memory unit is a large collection of storage cells with the circuits needed to move a word in or out. Random-access memory (RAM) can be written and read, and any word takes the same time to reach wherever it is (hence random access). This lesson describes the memory unit from the outside (its lines and operations), from the inside (cells, decoders, coincident selection), and shows how to build a large memory from small chips: the classic numerical question.
1. The Memory Unit
Memory unit block diagram
A memory of 2k words, each of n bits, has:
- k address lines selecting one word,
- n data input and n data output lines (often one shared bidirectional data bus),
- control lines: Read and Write (often one line, R/W'), plus a chip select / memory enable.
Capacity is stated as words × bits per word (e.g. 1K × 16) or in bytes (1K × 16 = 2048 bytes). Recall 1K = 210, 1M = 220, 1G = 230.
Find the number of address lines, data lines and the capacity in bytes for (a) 1K × 16, (b) 64K × 8, (c) a 4 GB byte-addressable memory.
- (a) 1K = 210: 10 address lines, 16 data lines, 1024 × 2 = 2048 bytes.
- (b) 64K = 216: 16 address lines (addresses 0000 to FFFF in hex), 8 data lines, 65,536 bytes.
- (c) 4G = 232 bytes, one byte per address: 32 address lines, 8 data lines.
2. Read and Write Operations
Write (store a word):
- Put the binary address on the address lines.
- Put the data bits on the data input lines.
- Activate the Write input (with chip select).
Read (fetch a word):
- Put the binary address on the address lines.
- Activate the Read input; after the access time the word appears on the output lines. Reading does not change the stored word.
| Enable | R/W' | Operation |
|---|---|---|
| 0 | X | none (outputs disconnected, high impedance) |
| 1 | 0 | write the selected word |
| 1 | 1 | read the selected word |
Write and read cycles
The access time is the time from a valid address to valid output data; the cycle time is the minimum time between the starts of two successive operations.
3. Inside a RAM
Each bit is stored in a binary cell (BC): a latch with gates that let it be selected, written and read. A 2k × n RAM is a 2k-by-n grid of cells. A k × 2k decoder selects one row (word); a column of n OR gates collects the selected word's bits for reading.
Internal organisation of a 4 × 4 RAM
Coincident (two-dimensional) decoding
A single decoder for a large memory is enormous: 1K words need a 10 × 1024 decoder with 1024 AND gates of 10 inputs. Coincident decoding splits the address into two halves that drive an X (row) decoder and a Y (column) decoder; a cell is selected where an active row meets an active column.
Coincident decoding of a 1K memory
Compare the decoder outputs needed for (a) a 1K-word memory and (b) a 4K-word memory using one decoder and using coincident decoding.
- (a) Linear: 210 = 1024 outputs. 2D: two 5 × 32 decoders, 32 + 32 = 64 outputs.
- (b) Linear: 212 = 4096 outputs. 2D: two 6 × 64 decoders, 64 + 64 = 128 outputs.
4. Static and Dynamic RAM
| SRAM | DRAM | |
|---|---|---|
| Cell | a latch (about 6 transistors) | one transistor + one capacitor |
| Holds data | as long as power is on | for a few milliseconds; must be refreshed |
| Density, cost per bit | low density, expensive | high density, cheap |
| Speed | fast | slower |
| Typical use | cache memory | main memory |
Both are volatile: data is lost when power is removed (unlike ROM and flash).
A DRAM chip saves pins by address multiplexing: the row half of the address is sent first and latched by RAS (row address strobe), then the column half on the same pins with CAS (column address strobe).
A 1M × 1 DRAM has 1024 rows and every row must be refreshed every 16 ms. (a) How many address pins does it need with multiplexing? (b) How often must a row refresh happen?
- (a) 1M = 220: 20 address bits, sent as 10 row bits then 10 column bits: 10 pins (plus RAS and CAS).
- (b) 1024 rows in 16 ms: one row every 16 / 1024 = 0.0156 ms = 15.6 µs.
5. Memory Expansion
Large memories are built from smaller chips in two directions:
- Word-length (width) expansion: chips side by side share the address and chip select; each supplies some of the bits. Two 256 × 4 chips make 256 × 8.
- Capacity (depth) expansion: rows of chips share the low address bits; the high address bits go to a decoder whose outputs drive the chip-select inputs, so exactly one row responds.
1K × 8 memory from eight 256 × 4 chips
Build a 1K × 8 memory from 256 × 4 RAM chips. How many chips, what decoder, and what is the address map?
- Chips: (1024 / 256) × (8 / 4) = 4 × 2 = 8.
- Address lines: 10 in total (A9 dots A0). Each chip uses 8 (A7 dots A0).
- The remaining 2 lines (A9 A8) go to a 2 × 4 decoder, one output per row of chips.
| A9 A8 | Row selected | Address range (hex) |
|---|---|---|
| 00 | row 0 | 000 to 0FF |
| 01 | row 1 | 100 to 1FF |
| 10 | row 2 | 200 to 2FF |
| 11 | row 3 | 300 to 3FF |
How many 16K × 8 chips are needed for a 64K × 16 memory? How many address lines go to each chip and to the decoder?
- Chips: (64K / 16K) × (16 / 8) = 4 × 2 = 8.
- Total address lines: 64K = 216, so 16.
- Each chip: 16K = 214, so 14 lines (A13 dots A0).
- Decoder: 16 - 14 = 2 lines, a 2 × 4 decoder for the 4 rows.
How many 128K × 8 chips make a 2 MB byte-addressable memory, and how large is the decoder?
- Chips: 2M / 128K = 221 / 217 = 16 (one chip per row, since both are 8 bits wide).
- Address lines: 21 in total, 17 to each chip, 21 - 17 = 4 to the decoder.
6. RAM and Memory Expansion in Verilog
A memory is declared as an array of registers: reg [3:0] mem [0:15] is 16 words of 4 bits. Writing is synchronous; reading here is combinational, with a high-impedance output (4'bz) when the chip is not selected, so several chips can share one data bus. The top module builds a 32 × 8 memory from four 16 × 4 chips, using A4 to select a row:
// A 16 x 4 RAM chip, and a 32 x 8 memory built from four of them
module ram16x4 (
input clk,
input cs, // chip select
input we, // 1 = write, 0 = read
input [3:0] addr,
input [3:0] din,
output [3:0] dout
);
reg [3:0] mem [0:15];
integer i;
initial begin
for (i = 0; i < 16; i = i + 1)
mem[i] = 4'b0000;
end
always @(posedge clk) begin
if (cs && we)
mem[addr] <= din; // synchronous write
end
assign dout = (cs && !we) ? mem[addr] : 4'bz; // tri-state output when not selected
endmodule
module mem32x8 (
input clk,
input we,
input [4:0] addr,
input [7:0] din,
output [7:0] dout
);
wire row0 = ~addr[4], row1 = addr[4]; // 1-to-2 decoder on the top address bit
// each row: two chips side by side give 8-bit words (high nibble, low nibble)
ram16x4 c0h (.clk(clk), .cs(row0), .we(we), .addr(addr[3:0]), .din(din[7:4]), .dout(dout[7:4]));
ram16x4 c0l (.clk(clk), .cs(row0), .we(we), .addr(addr[3:0]), .din(din[3:0]), .dout(dout[3:0]));
ram16x4 c1h (.clk(clk), .cs(row1), .we(we), .addr(addr[3:0]), .din(din[7:4]), .dout(dout[7:4]));
ram16x4 c1l (.clk(clk), .cs(row1), .we(we), .addr(addr[3:0]), .din(din[3:0]), .dout(dout[3:0]));
endmodule
module tb;
reg clk = 0, we = 0;
reg [4:0] addr;
reg [7:0] din;
wire [7:0] dout;
mem32x8 m (.clk(clk), .we(we), .addr(addr), .din(din), .dout(dout));
task write(input [4:0] a, input [7:0] d);
begin
addr = a;
din = d;
we = 1;
#5 clk = 1;
#5 clk = 0;
we = 0;
$display("write %h to address %0d (chip row %0d)", d, a, a[4]);
end
endtask
task read(input [4:0] a);
begin
addr = a;
#1 $display("read address %0d -> %h", a, dout);
end
endtask
initial begin
write(5'd3, 8'hA7);
write(5'd19, 8'h3C);
read(5'd3);
read(5'd19);
read(5'd4);
end
endmoduleAddress 3 lands in the first row of chips and address 19 in the second; address 4 was never written:
write a7 to address 3 (chip row 0)
write 3c to address 19 (chip row 1)
read address 3 -> a7
read address 19 -> 3c
read address 4 -> 00Key points to remember
- 2k × n memory: k address lines, n data lines; 1K = 210.
- Write: address, data, Write. Read: address, Read, wait the access time.
- Coincident decoding: X and Y decoders, 2 · 2k/2 outputs instead of 2k.
- SRAM = latch, fast, cache; DRAM = capacitor, dense, needs refresh, main memory.
- Chips = (words ratio) × (bits ratio); the extra high address bits drive a decoder for chip select.
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Draw the block diagram of a memory unit and explain the read and write operations. (5 Marks)
- Q2. Explain the internal construction of a 4 × 4 RAM with a binary cell. (10 Marks)
- Write: the binary cell (latch, select, read/write gates), the 2 × 4 decoder, the 4 × 4 grid, the output OR gates.
- Q3. What is coincident decoding? How many decoder outputs does a 4K memory need with and without it? (5 Marks)
- Q4. Design a 1K × 8 memory using 256 × 4 RAM chips. Draw the diagram and the address map. (10 Marks)
- Q5. Compare SRAM and DRAM. Why does DRAM need refreshing? (5 Marks)