Electronic – Please explain the details of cache circuit addressing

cache

My cache can have 32 address bits with 2 bits for index and 3 bits for byte-offset.

Associativity 2, block size 8.

Of course, the the bits for index says which row of the cache the data is.

But how do I know which block when there are 2 blocks (associativity 2)?

The 3 bits byte-offset only tells which byte within a block and there are 2 blocks.

Is there a comparator that determines which of the blocks has the tag that matches the incoming request for data?

Best Answer

Yes, that's exactly what the tag is for. With 2-way associativity, you have two comparators so that you can tell which of the two blocks (if any) contains the data you're looking for. Each tag and each comparator needs to be wide enough to handle all of the address bits left over after you remove the byte-index and cache-index bits. In your case that would be 32 – 3 – 2 = 27 bits.