Direct-Mapped Cache Final Contents for a Given Access Sequence (8 Lines)

Direct-Mapped Cache Final Contents for a Given Access Sequence (8 Lines)

Verified Sources
Nov 4, 2026

We analyze a Direct-mapped cache with 8 cache blocks/lines numbered 00–77. For each requested memory block number mm, the cache line index is determined by mapping via:

  • Index: i=m mod 8i = m \bmod 8
  • Tag: tag=⌊m/8⌋\text{tag} = \lfloor m/8 \rfloor Because it is direct-mapped, each access to memory block mm overwrites whatever was previously in line ii. This is the core Replacement behavior: conflicts always evict the existing cache line contents.

Below, we track which memory block ends up residing in each cache line after the full sequence: 3,5,2,8,0,63,9,16,20,17,25,18,30,24,2,63,5,82,17,24.3, 5, 2, 8, 0, 63, 9, 16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82, 17, 24.

Key mapping terms: Cache line index; Conflict; Valid bit.3

Footnotes

  1. Wikipedia: Cache (computing) — Mapping and replacement concepts - Background on cache lines, hits/misses, and mapping. ↩

  2. Wikipedia: Direct-mapped cache - Direct-mapped mapping and how an address selects a cache line. ↩

  3. Wikipedia: Cache replacement policies / eviction on conflict (conceptual) - Replacement behavior including eviction when lines conflict. ↩

Direct-Mapped Cache Mapping (Conceptual Walkthrough)

Compute final cache-line contents by modulo mapping

  1. 1
    Step 1

    Assume all 8 lines start invalid; after the first access to a line, it becomes valid with the accessed memory block.

  2. 2
    Step 2

    Direct-mapped rule: block mm resides in line i=m mod 8i=m\bmod 8 and overwrites that line.

  3. 3
    Step 3

    Record that line ii now contains memory block mm (tag matches automatically after overwrite for final state).

  4. 4
    Step 4

    At the end, each cache line contains the last memory block in the sequence that mapped to that line.

Tracking the last write to each cache line

For each access mm, compute i=mbmod8i=m\\bmod 8:

Access #Memory block mmLine i=mbmod8i=m\\bmod 8Line overwritten by
133line 3 ← 3
255line 5 ← 5
322line 2 ← 2
480line 0 ← 8
500line 0 ← 0
6637line 7 ← 63
791line 1 ← 9
8160line 0 ← 16
9204line 4 ← 20
10171line 1 ← 17
11251line 1 ← 25
12182line 2 ← 18
13306line 6 ← 30
14240line 0 ← 24
1522line 2 ← 2
16637line 7 ← 63 (no change in line 7’s resident value)
1755line 5 ← 5 (reaffirm)
18822line 2 ← 82
19171line 1 ← 17
20240line 0 ← 24 (reaffirm as last)

Thus, the final resident memory block number in each cache line is the last one written to that line.

Final cache contents by cache line (direct-mapped, 8 lines)

Each line i ends holding the last accessed memory block m such that m mod 8 = i.

How to do it quickly

You only need the last occurrence in the sequence for each residue class m mod 8m\bmod 8. Everything earlier to the same line is guaranteed evicted in a direct-mapped cache.

Avoid a common mistake

Do not treat the cache like it has 8-way capacity for 8 distinct blocks. Direct-mapped means one block per line; later conflicts overwrite earlier contents.

Key concepts used in the computation

Finalization process (end state) across the access sequence

Line 0 first filled

After Access 4 (8)

Line 0 becomes 8, but it can still be overwritten later."

Line 0 updated to 24

After Access 14 (24)

Line 0 is overwritten again at the end; keep tracking last writes."

Line 2 updated to 82

After Access 18 (82)

Since 82 mod 8=282\bmod 8=2, this becomes the last line-2 update."

End state locked

Final Access (24)

Line 0 is reaffirmed by the final access; other lines retain their last mapped values."

Knowledge Check

Question 1 of 4
Q1Single choice

In a direct-mapped cache with 8 lines, a memory block m maps to which cache line index?