- Asked 3/22
- 2074 Chaitra · 6 marks
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).
| Block | Block address (5 bits) | Tag (2) | Line (3) | Cache line | Action |
|---|---|---|---|---|---|
| 0 | 00000 | 00 | 000 | 0 | loaded into empty line |
| 1 | 00001 | 00 | 001 | 1 | loaded into empty line |
| 2 | 00010 | 00 | 010 | 2 | loaded into empty line |
| 3 | 00011 | 00 | 011 | 3 | loaded into empty line |
| 4 | 00100 | 00 | 100 | 4 | loaded into empty line |
| 5 | 00101 | 00 | 101 | 5 | loaded into empty line |
| 6 | 00110 | 00 | 110 | 6 | loaded into empty line |
| 7 | 00111 | 00 | 111 | 7 | loaded into empty line |
| 8 | 01000 | 01 | 000 | 0 | replaces block 0 |
| 9 | 01001 | 01 | 001 | 1 | replaces block 1 |
| 10 | 01010 | 01 | 010 | 2 | replaces block 2 |
| 11 | 01011 | 01 | 011 | 3 | replaces block 3 |
Final cache contents:
| Cache line | Block held | Tag |
|---|---|---|
| 0 | B8 | 01 |
| 1 | B9 | 01 |
| 2 | B10 | 01 |
| 3 | B11 | 01 |
| 4 | B4 | 00 |
| 5 | B5 | 00 |
| 6 | B6 | 00 |
| 7 | B7 | 00 |
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)
Related questions
- Direct mapping with 32-block memory, 10 blocks used · Computer Organization and Architecture, chapter 6 · asked 3×
- Direct mapping with 64-block memory, 10 blocks used · Computer Organization and Architecture, chapter 6 · asked 3×
- Cache read and direct-mapping demerits · Computer Organization and Architecture, chapter 6
- Direct cache mapping · Computer Organization and Architecture, chapter 6 · asked 3×
- Cache memory mapping techniques · Embedded System, chapter 4 · asked 3×
All Computer Organization and Architecture chapter 6 questions →