Cpu Design Questions
The main difference between a direct-mapped cache and a set-associative cache lies in the way they map memory addresses to cache locations.
In a direct-mapped cache, each memory address is mapped to a specific cache location. This means that there is a one-to-one correspondence between memory blocks and cache blocks. As a result, if two memory blocks have the same index, they will be mapped to the same cache block, leading to a potential conflict.
On the other hand, in a set-associative cache, each memory address can be mapped to multiple cache locations. The cache is divided into sets, and each set contains multiple cache blocks. The mapping is done using a combination of the memory block's index and a set index. This allows for more flexibility and reduces the chances of conflicts, as multiple memory blocks can be mapped to different cache blocks within the same set.
Overall, the key difference is that a direct-mapped cache has a one-to-one mapping between memory and cache blocks, while a set-associative cache allows for multiple memory blocks to be mapped to different cache blocks within the same set.