Skip to main content

Direct mapping with 32-block memory, 10 blocks used

Short answer

Direct mapping: block j placed in line j mod 8. For blocks 0–9 accessed sequentially, blocks 0–7 fill lines 0–7; block 8 replaces block 0 in line 0, block 9 replaces block 1 in line 1. Final cache: line0 holds B8 (tag 01), line1 B9 (tag 01), lines2–7 hold B2–B7 (tag 00).

Suppose main memory has 32 blocks and cache memory has 8 blocks. When 10 blocks of main memory are used, show how mapping is performed in the direct mapping technique.

In direct mapping a main-memory block j goes to cache line (j mod 8). Main memory has 32 blocks, so a block address has 5 bits; the cache has 8 lines, so the line field has 3 bits and the tag has 5-3 = 2 bits.

Block address = Tag (2) | Line (3)

Assumption: the 10 blocks used are blocks 0 to 9, accessed in order.

BlockBlock address (5 bits)Tag (2)Line (3)Cache lineAction
000000000000loaded into empty line
100001000011loaded into empty line
200010000102loaded into empty line
300011000113loaded into empty line
400100001004loaded into empty line
500101001015loaded into empty line
600110001106loaded into empty line
700111001117loaded into empty line
801000010000replaces block 0
901001010011replaces block 1

Final cache contents:

Cache lineBlock heldTag
0B801
1B901
2B200
3B300
4B400
5B500
6B600
7B700

Blocks that differ by a multiple of 8 compete for the same line (for example block 0 and block 8). The tag stored with each line tells which of these blocks is present. A block is a hit if the line's tag equals the tag of the address; no replacement algorithm is needed because each block has only one possible line.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Organization and Architecture chapter 6 questions →