Skip to main content

Direct mapping with 32-block memory, 8-block cache

Short answer

In direct mapping with 32 main blocks and 8 cache lines, line = block mod 8. Accessing blocks 0–11 sequentially fills lines 0–7, then blocks 8–11 overwrite lines 0–3. Final cache: lines 0–3 hold blocks 8–11 (tag 01), lines 4–7 hold blocks 4–7 (tag 00).

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

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 12 blocks used are blocks 0 to 11, accessed in order 0, 1, 2, ..., 11 (the first access of each block is a miss).

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
1001010010102replaces block 2
1101011010113replaces block 3

Final cache contents:

Cache lineBlock heldTag
0B801
1B901
2B1001
3B1101
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 →