In: Computer Science
A direct mapped cache has 16 blocks and block size is 64-bits (8 bytes).
a. Where will the memory block 45 reside in cache? (5
b. Where will be the memory address 1667 mapped in cache
SOLUTION
In a directed mapped cache , consecutive memory locations are stored in form of blocks inside the cache in a defined order. A cache with N blocks will try to store N memory blocks inside it (for faster memory accesses later on) and this storage of blocks is done systematically and consecutively. Whenever a memory block that needs to be accessed and is not currently in the cache , it is accessed from the main memory and this step is called a cache miss. On the contrary , if one of the blocks contains the address that needs to be accessed , then the address is accessed much wuickly from the cache and this step is called a cache hit.
PROBLEM A :
Cache can only store = 16 blocks.
Each block has memory = 64 bits = 8 bytes.
Assuming the memory to be byte addressable , the cache has = 16*8 bytes = 128 bytes of memory.
Now , blocks are placed consecutively inside a cache. Block number (1,2,......,15,16) is stored in the cache and if we need to access some other block, then all 16 blocks are replaced.
For eg: we want to access Block number 22 , then Cache will be replaced with (17,18,....31,32).
So , we can see that Block number B will be at a position B%16.
Therefore , block number 45 would be at = 45 MOD 16 = 13th position in the cache.
PROBLEM B :
Assuming the memory to be byte adressable ,
1667th memory adddress is present in = 1667/8 = 208.375th block.
Now , 208th block is present at 208 MOD 16 = 0th block ( which is nothing but the 16th block , as X MOD Y becomes 0 when X is a multiple of Y)
Hence , 1667th memory address is present in 16th block.