A student keeps the notebook for today on the desk, the notes for the term in the bag and the old books in the cupboard. The nearer a thing is, the quicker it can be reached but the less of it can be kept. A computer arranges memory in just this way.
Memory Hierarchy
The memory hierarchy is the arrangement of the memory of a computer in levels, from small and fast to large and slow. At the top are the processor registers and the cache, below them the main memory, and at the bottom the auxiliary memory. The cost per bit falls and the capacity rises as we go down. The hierarchy works because programs show locality of reference: they use the same data and nearby data again and again over a short time.
Definition: Memory hierarchy. The organisation of computer storage into levels of differing speed, size and cost, so that frequently used data is kept in the faster levels.
Main Memory
Main memory holds the programs and data in use. RAM (random access memory) can be read and written. Static RAM keeps its data while the power is on, and dynamic RAM stores a bit as a charge that must be refreshed. ROM (read-only memory) holds fixed programs, such as the start-up program. Its types include PROM, EPROM and EEPROM, which can be programmed or erased in different ways. A large memory is built from chips, and a decoder uses the high address lines to choose the chip.
Auxiliary Memory
Auxiliary memory stores large amounts of data permanently. The commonest device is the magnetic disk, in which data is recorded in circular tracks divided into sectors. Magnetic tape stores data in sequence and is used for backup. Auxiliary memory is much slower than main memory, and its data must be brought into main memory before the processor can use it.
Table 4.10: Levels of the memory hierarchy
| Level | Speed | Capacity | Cost per bit |
|---|---|---|---|
| Registers | Fastest | Very small | Highest |
| Cache | Very fast | Small | High |
| Main memory | Fast | Medium | Medium |
| Auxiliary memory | Slow | Very large | Lowest |
Example 4.9: Building a memory from chips
Problem: A memory of 512 bytes is to be built from RAM chips of 128 bytes each. Find the number of chips and the address lines needed.
Solution:
- Number of chips = 512 / 128 = 4.
- Each chip needs 7 address lines, since 2 to the power 7 is 128.
- The total memory needs 9 address lines, since 2 to the power 9 is 512.
- The two remaining lines go to a 2-to-4 decoder that selects one of the four chips.
Result: Four chips are used, with 7 lines shared by all chips and 2 lines into the decoder.
import math
size, chip = 512, 128
print(size // chip, int(math.log2(chip)), int(math.log2(size)))
Output
4 7 9
Common mistakes
- Believing that auxiliary memory can be addressed directly by the processor like main memory.
- Mixing up RAM, which can be written, and ROM, which is read-only.
- Forgetting that a decoder selects the chip from the high address lines.
Key takeaways
- The hierarchy runs from registers to cache, main memory and auxiliary memory.
- Higher levels are faster, smaller and costlier per bit.
- Locality of reference makes the hierarchy work.
- RAM is volatile and ROM holds fixed programs.
Practice questions
- Why does the memory hierarchy work?
- Name two types of ROM.
- What is the commonest auxiliary memory device?
Answers to the practice questions
- Programs show locality of reference, reusing the same and nearby data over short times.
- PROM and EPROM (or EEPROM).
- The magnetic disk.
Sources
- Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit IV
