A computer system has a 4-way set associative cache with one-word blocks. The…

A computer system has a 4-way set associative cache with one-word blocks. The total cache capacity is 256 bytes. The sequence of byte addresses accessed by the CPU is:

8, 64, 96, 128, 64, 96, 256, 192, 24

Answer the following:

  1. Determine the number of sets in the cache.

  2. Identify the set number for each memory reference.

  3. Show the step-by-step cache contents after each access.

  4. Calculate the total number of cache hits and misses.

  5. Write the final cache state.

Attempted by 5 students.

Show answer & explanation
  1. Given parameters
    Cache size = 256 bytes
    Block size = 1 word = 4 bytes
    Associativity = 4-way

  2. Number of blocks in cache

Cache blocks = Cache size / Block size
= 256 / 4
= 64 blocks

  1. Number of sets

Sets = Blocks / Associativity
= 64 / 4
= 16 sets

  1. Mapping rule

Set number = Block number mod Number of sets

  1. Address breakdown diagram

Main Memory Address
| Block Number | Word Offset |
  1. Access sequence analysis

Address   Block   Set   Result
8         2       2     Miss
64        16      0     Miss
96        24      8     Miss
128       32      0     Miss
64        16      0     Hit
96        24      8     Hit
256       64      0     Miss
192       48      0     Miss
24        6       6     Miss
  1. Final cache state (only filled sets)

Set 0 : m[64], m[128], m[256], m[192]
Set 2 : m[8]
Set 6 : m[24]
Set 8 : m[96]
  1. Cache behavior explanation

    The cache allows four blocks per set, which reduces conflict misses compared to direct mapping.

  2. Results

Total hits = 2

Total misses = 7

  1. Conclusion

    Set associative mapping improves cache utilization because multiple blocks mapping to the same set can coexist, reducing replacement conflicts and improving performance.

Explore the full course: Zero To Hero

Loading lesson…