The cache parameters are:
- Block size (line size) = 64 bytes.
- Number of cache lines = 32.
- Main memory address bits: 16 (216 bytes).
- Offset bits: log2(64)=6 bits.
- Index bits: log2(32)=5 bits.
- Tag bits: 16−5−6=5 bits.
The array is 50x50 bytes, so its total size is 50×50=2500 bytes.
The number of cache blocks required to store the array is ⌈642500⌉=40 blocks.
The array starts at memory location 1100H. Let Bk denote the k-th block of the array (for k=0,…,39).
The memory address of the start of Bk is Addrk=1100H+k×64.
The block number in main memory for Bk is BlockNumk=64Addrk=641100H+k=644352+k=68+k.
For a direct-mapped cache, the cache index and tag for Bk are:
- Indexk=BlockNumk(mod32)=(68+k)(mod32)
- Tagk=⌊32BlockNumk⌋=⌊3268+k⌋
First Access (Array accessed for the first time):
Since the cache is initially empty, every access to a new block will be a compulsory miss.
There are 40 blocks in the array, so there will be 40 misses in the first access.
Total misses for first access = 40.
After the first access, the cache will contain the blocks that were loaded and not evicted by subsequent accesses during this pass. Let's determine the final state of the cache:
- For k=0…27: Indexk=(68+k)(mod32) ranges from 4(mod32)=4 to 95(mod32)=31. Tagk=⌊(68+k)/32⌋=⌊68/32⌋=2.
- These 28 blocks (B0…B27) occupy cache lines 4…31 with Tag 2.
- For k=28…39: Indexk=(68+k)(mod32) ranges from 96(mod32)=0 to 107(mod32)=11. Tagk=⌊(68+k)/32⌋=⌊96/32⌋=3.
- These 12 blocks (B28…B39) occupy cache lines 0…11 with Tag 3.
Conflicts during the first pass:
- Blocks B0…B7 (Tag 2) map to lines 4…11.
- Blocks B32…B39 (Tag 3) also map to lines 4…11. Since B32…B39 are accessed after B0…B7, and their tags are different (3 vs 2), B32…B39 will evict B0…B7 from lines 4…11.
So, after the first access, the cache contains:
- Lines 0…3: Contain blocks B28…B31 (Tag 3). (4 blocks)
- Lines 4…11: Contain blocks B32…B39 (Tag 3), which evicted B0…B7. (8 blocks)
- Lines 12…31: Contain blocks B8…B27 (Tag 2), as no later blocks map to these lines. (20 blocks)
Total blocks in cache = 4+8+20=32 blocks. The cache is full.
Second Access (Array accessed for the second time):
The array is accessed again in order B0,B1,…,B39.
- Access B0…B7 (8 blocks):
- These blocks map to lines 4…11 with Tag 2.
- Current cache lines 4…11 hold B32…B39 (Tag 3).
- The tags (2 vs 3) do not match. Each access will be a miss. These 8 blocks (B0…B7) are loaded, evicting B32…B39.
- Misses = 8.
- Access B8…B27 (20 blocks):
- These blocks map to lines 12…31 with Tag 2.
- Current cache lines 12…31 already hold B8…B27 (Tag 2).
- The tags match. Each access will be a hit.
- Misses = 0.
- Access B28…B31 (4 blocks):
- These blocks map to lines 0…3 with Tag 3.
- Current cache lines 0…3 already hold B28…B31 (Tag 3).
- The tags match. Each access will be a hit.
- Misses = 0.
- Access B32…B39 (8 blocks):
- These blocks map to lines 4…11 with Tag 3.
- During the access of B0…B7 in this second pass, lines 4…11 were updated to hold B0…B7 (Tag 2).
- The tags (3 vs 2) do not match. Each access will be a miss. These 8 blocks (B32…B39) are loaded, evicting B0…B7.
- Misses = 8.
Total misses for second access = 8+0+0+8=16.
Total data cache misses = (Misses in first access) + (Misses in second access)
Total data cache misses = 40+16=56.
The final answer is 56.