# What determines a hit or a miss for direct mapped cache?

I've been stuck on this for a while now, I've tried reading the related topics on cs.stackexchange as well as the textbook and youtube videos.

Suppose we have a 8KB direct-mapped data cache with 64-byte blocks.

Offset $= log_2(64) = 6$ bits

number of blocks $= 8k / 64 = 125$

$Index = 7$ bits

$Tag = 32 – 13 = 19$ bits

Then how do I tell whether or not I have a hit or a miss given an address? Is it (Block address) modulo (Number of blocks in the cache)

Where block address = byte address / bytes per blocks?

For example if (block address) mod (number of blocks in cache) = 2, then does that mean row 2 of my picture is a hit?

• Please do not use images as the main content. We have LaTeX available. – Evil Dec 9 '16 at 11:39
• 8kB / 64 = 128. In addition to address bits, each tag has a Valid bit which is cleared at startup then set for each loaded block. Assuming an empty cache at the beginning, the 1st and 2nd accesses are misses, the third is a hit because the block "0100101" has already been loaded and the tags are equal. – TEMLIB Dec 10 '16 at 1:08