Computer Organisation and Architecture · Direct Mapped Cache
Direct Mapping of Main Memory Blocks to Cache Lines
Overview
Mapping is the rule that decides which cache line a main-memory block is placed in.
Because main memory has far more blocks than the cache has lines (16 blocks vs 4 lines in the example), not all blocks can be held at once, so a fixed placement rule is needed.
Direct mapping is the simplest such rule: each block is permanently assigned to exactly one cache line by a modulo (round-robin) scheme.
Key concepts
- Mapping: the rule that fixes the position a main-memory block may occupy whenever it is brought into the cache.
- Direct mapping: each main-memory block is permanently assigned to exactly one cache line, decided by a round-robin (modulo) rule.
- Block number: the upper 4 bits of the 6-bit physical address; identifies which main-memory block is referenced.
- Block offset: the lower 2 bits of the address; identifies the word inside the block (block size = 4 words, so 2 offset bits).
- Cache lines: the cache has 4 lines, numbered line 0 to line 3.
- Many-to-one function: several main-memory blocks map to the same cache line; the assignment does not mean all 16 blocks sit in the cache at once.
Whenever block 0 is fetched it must go into line 0, and whenever block 4 is fetched it must also go into line 0 (likewise 8 and 12). - Tag: the remaining upper bits of the block number, stored to identify which of the several blocks mapped to the same line is currently in that line.
- Line selection rule: the two least significant bits of the block-number part (not of the whole address) directly give the cache line number.

How it works
- Split the 6-bit physical address into a 4-bit block number (upper bits) and a 2-bit block offset (lower bits).
- Number the 4 cache lines 0, 1, 2, 3.
- Assign blocks round-robin: block 0 → line 0, block 1 → line 1, block 2 → line 2, block 3 → line 3, then block 4 → line 0 again, block 5 → line 1, and so on up to block 15.
- The resulting many-to-one picture:
- Line 0 ← blocks 0, 4, 8, 12
- Line 1 ← blocks 1, 5, 9, 13
- Line 2 ← blocks 2, 6, 10, 14
- Line 3 ← blocks 3, 7, 11, 15
- Write the 4-bit block numbers in binary and read the two least significant bits of the block number:
| Block number | Binary (4 bits) | Two LSBs of block number | Cache line |
|---|---|---|---|
| 0 | 0000 | 00 | 0 |
| 1 | 0001 | 01 | 1 |
| 2 | 0010 | 10 | 2 |
| 3 | 0011 | 11 | 3 |
| 4 | 0100 | 00 | 0 |
| 5 | 0101 | 01 | 1 |
| 6 | 0110 | 10 | 2 |
| 7 | 0111 | 11 | 3 |
| 8 | 1000 | 00 | 0 |
| 9 | 1001 | 01 | 1 |
| 10 | 1010 | 10 | 2 |
| 11 | 1011 | 11 | 3 |
| 12 | 1100 | 00 | 0 |
| 13 | 1101 | 01 | 1 |
| 14 | 1110 | 10 | 2 |
| 15 | 1111 | 11 | 3 |
- Blocks 0, 4, 8, 12 all have 00 in the two least significant bits of their block number, and only these four blocks do, so they always occupy line 0. Blocks 1, 5, 9, 13 have 01 and only they do → line 1.
Blocks 2, 6, 10, 14 have 10 → line 2. Blocks 3, 7, 11, 15 have 11 → line 3. - The organization is convenient because the address splits mechanically: the least 2 bits are the block offset, the remaining 4 bits are the block number, the two least significant bits of the block number give the line number, and the remaining upper bits of the block number form the tag.
Formulas
-
, where Block number is the main-memory block address and Number of cache lines = cache size / block size.
-
bits
-
bits
-
bits (taken from the LSBs of the block number)
-
bits
-
-
Address split and line selection
Drawing the diagram…
-
Shows how the 6-bit address splits into block number and offset, with the block number's two LSBs selecting the cache line and the upper bits forming the tag.
-
Blocks mapped to each cache line
Drawing the diagram…
- Shows the many-to-one direct mapping of the 16 main-memory blocks onto the 4 cache lines.
Worked examples
Which line does block 13 go to?
- Block number 13 in 4-bit binary = 1101.
- Two least significant bits of the block number = 01.
- Therefore block 13 always goes to cache line 1 (together with blocks 1, 5, 9).
- The remaining upper bits of the block number (11) form the tag.
Which blocks share line 0?
- Line 0 requires the two LSBs of the block number to be 00.
- Block numbers with 00 in the last two positions: 0000 (0), 0100 (4), 1000 (8), 1100 (12).
- So blocks 0, 4, 8, 12 all map to line 0; no other block ever maps there.
Comparison
| Aspect | Direct mapping (this scheme) |
|---|---|
| Position of a block | Fixed: exactly one line, given by block number mod number of lines |
| Type of function | Many-to-one (4 main-memory blocks per cache line in the example) |
| Line selection | Two LSBs of the block number |
| Tag | Remaining upper bits of the block number, stored to identify which block is in the line |
| Advantage | Simplest mapping; address split is mechanical, so lookup is fast and cheap |
| Limitation | Blocks sharing a line evict each other even if other lines are free (conflict misses) |
Revision summary
- Mapping answers: which cache line does a main-memory block go into? Direct mapping is the simplest answer.
- Example parameters: 16 main-memory blocks, 4 cache lines, block size 4 words, 6-bit address → 4-bit block number + 2-bit block offset.
- Rule: line number = block number mod number of lines; here the two LSBs of the block number give the line.
- Fixed assignment: 0, 4, 8, 12 → line 0; 1, 5, 9, 13 → line 1; 2, 6, 10, 14 → line 2; 3, 7, 11, 15 → line 3.
- The mapping is many-to-one: a block is always placed in its one fixed line whenever it is fetched, not all blocks resident at once.
- Trap: the two LSBs used for the line number come from the block-number part only, not from the whole address.
- The remaining upper bits of the block number become the tag, identifying which competing block currently occupies the line.
- Cache is a very frequently asked exam topic (at least one question every year); the questions are easy once the address split and mapping rule are clear, so learn them thoroughly.
Previous-year exam insights
- For a byte-addressable direct-mapped cache, split the physical address as tag | line/index | block offset.
Offset bits = ;
index/line bits = ;
tag bits = total physical address bits - offset bits - index bits, where total physical address bits = .
Asked inGATE 2026GATE 2022GATE 2007ISRO 2011 - Number of cache lines = cache size / block size.
For byte addressing, block number = floor(byte address / block size) and cache line/index = block number mod number of cache lines;
when the number of lines is a power of two, this modulo is simply the low index bits of the block number.
Asked inGATE 2026ISRO 2011 - In a direct-mapped cache there is exactly one candidate line for a block and no replacement policy choice: on a miss (including the first cold-start reference) the requested block must replace whatever block currently occupies that line; later references hit only if that block has not since been evicted.
Asked inGATE 2026GATE 2022 - Two different blocks conflict in a direct-mapped cache exactly when their block numbers are congruent modulo the number of cache lines; equivalently, their block start addresses differ by a multiple of the cache size (number of lines × block size).
Such blocks evict each other even if other cache lines are free.
Asked inGATE 2026GATE 2022GATE 2007 - On a direct-mapped access, the index bits select the line, and a cache hit requires valid bit = 1 and stored tag = address tag;
otherwise it is a miss and the block is fetched.
Standard cache mapping schemes are direct, fully associative and set-associative; segmented/page mapping is not a cache mapping scheme.
Asked inGATE 2026GATE 2022GATE 2007UGC NET 2018 - For row-major two-dimensional arrays, consecutive elements in a row are contiguous in memory, so one cache block loads several consecutive elements.
In nested-loop row scans, compulsory misses occur on the first element of each new block, and extra conflict misses occur when addresses from different rows or strides map to the same direct-mapped cache line; use the address-split and modulo mapping formula to count them.
Asked inGATE 2007ISRO 2017