Question 1
Exercise 2
Do not fret! This question, and even the next, is rather easy. Let us begin!
Q) Suppose a computer using direct-mapped cache has 232 bytes of byte-addressable main memory and a cache of 1024 blocks, where each cache block contains 32 bytes.
a) How many blocks of main memory are there?
We have a total of 232 bytes of byte-addressable main memory. Likewise, each cache block contains 32 bytes which is the equivalent of 25 bytes.
We just need to divide our total bytes of byte-addressable main memory by the number of bytes contained in each cache block.
The answer then is: 232 / 25 = 227 = 134217728 blocks of main memory.
b) What is the format of a memory address as seen by the cache; that is, what are the sizes of the tag, block, and offset fields?
The offset is merely the number of bytes in each cache block. So, 25 for 32 bytes. The offset contains 5 bits.
The block is merely the number of cache blocks that we have. 210 = 1024. The block contains 10 bits.
The tag is what's left over. So, since we have 232 bytes of byte-addressable main memory we simply subtract the number of bits from the offset and block from 32. 32 - 5 - 10 = 17. Tag contains 17 bits.
Tag has 17 bits, block has 10 bits, and offset has 5 bits.
c) To which cache block will the memory address 0x000063FA map?
Using this converter, the given hex value is represented by 110001111111010 in binary.
Tag | Block | Offset
00000000000000000 | 1100011111 | 11010
I hope the above renders correctly. In any case, notice that tag has 17 bits, block has 10 bits, and offset has 5 bits.
The block has the bit pattern 11000111112 = 79910.
The answer is cache block 799.
Question 2
Exercise 5
This question is pretty much just the last one but with associative cache. You'll find it to be even simpler than the other question!
Q) Suppose a computer using fully associative cache has 224 bytes of byte-addressable main memory and a cache of 128 blocks, where each cache block contains 64 bytes.
a) How many blocks of main memory are there?
Just like before, we're gonna divice the number of bytes of byte-addressable main memory by the size of each cache block.
Remember, 64 = 26.
The answer is: 224 / 26 = 218 = 262144 blocks of memory.
b) What is the format of a memory address as seen by the cache; that is, what are the sizes of the tag and offset fields?
Associate cache is special because there is block! We only have tag and offset and we figure out the number of bits for them just as we did for the last question.
For offset, we know that each block contains 64 bytes which is equal to 26 bytes. Therefore, we need 6 bits in the offset.
Tag is just everything that remains. So, we have a total of 224 bytes of byte-addressable main memory. Take that and subtract the number of bits required for the offset like so: 24 - 6 = 18. The tag needs 18 bits.
Tag has 18 bits and offset has 6 bits.
c) To which cache block will the memory address 0x01D872 map?
Trick question! We do not map to a block as we did we direct mapped cache. This is fully associative cache. Instead of mapping to a certain block, we just fill things in as we go. As such, it can be mapped anywhere!
Once again, the answer is it can be mapped anywhere! Don't forget it!