Consider a machine with a byte addressable main memory of bytes. Assume that a direct mapped data cache consisting of lines of bytes each is used in the system. A x two-dimensional array of bytes is stored in the main memory starting from memory location . Assume that the data cache is initially empty. The complete array is accessed twice. Assume that the contents of the data cache do not change in between the two accesses.
Which of the following lines of the data cache will be replaced by new blocks in accessing the array for the second time?
View worked solution
Answer: A
To determine which cache lines are replaced during the second access, we first identify the memory blocks occupied by the array.
1. Cache and Array Parameters:
- Cache line size: bytes
- Number of cache lines:
- Array starting address:
- Array size: bytes
- Array ending address:
2. Memory Blocks Occupied:
- Starting Block:
- Ending Block:
The array spans memory blocks, from Block to Block .
3. Cache Mapping ():
- Blocks to map to cache lines to , and then to .
- Blocks to map to cache lines to .
4. First Access Pass:
- Blocks to are loaded into cache lines to and to .
- Blocks to are then loaded, overwriting lines to .
- At the end of the first pass, lines to contain Blocks to , while lines to and to contain Blocks to .
5. Second Access Pass:
- Accessing Blocks to (mapping to lines to ) results in misses, replacing Blocks to with Blocks to .
- Accessing Blocks to results in cache hits.
- Accessing Blocks to results in misses, replacing Blocks to with Blocks to .
Thus, only line 4 to line 11 are replaced during the second pass.
Free practice · Your answers on this page are not saved.
