How to find number of bits in tag field of cache block

Viewed 10825

I have this question from class.

"Main memory has 2048 bytes. The total cache size is 64 bytes, among which are a total of 8 blocks. How many bits is the tag field of each cache block?"

How do I go about solving this? I've looked all over stack overflow and all the answers I could find involve using information I don't have available to me or uses methods that were never taught in class such as using logarithms.

1 Answers
  1. Calculate the size of each address in m bits. If main memory has 2048 bytes, then we have 2048=2^m unique addresses. This can be calculated as log2(2048) = 11 bits per address. (2^11=2048)

  2. Calculate bit offset n from the number of bytes in a block. 64 bytes/8 blocks = 8 bytes per block. 2^n=8, or log2(8). So n=3, and the block offset is 3 bits.

  3. Calculate the set index s. Since we are not told otherwise, assume this is a direct mapped cache. This means we have 8 sets with 1 block in each set. 2^s=8, or log2(8)=3. So s=3.

  4. Finally, we know the number of tag bits is T=m-s-n. Therefore when m=11, s=3, and n=3, T=11-6=5.

There are a total of 5 tag bits.

You will have to use logarithms unless you can calculate 2^m=2048 in your head. I tried to show each calculation in 2 ways so you can see what is going on. When you calculate log2(2048), this is the same as 2^m=2048.

If my assumtion that we're in the same class is true, check out 6.4 from the CSAPP book.

Related