In: Computer Science
A direct mapped cache has 32 cache lines.Each cache line consists of 4 words, and each word is four bytes.The address bus consists of 16 bits.
How many bits are required for the tag in this direct-mapped cache?
Solution:
Given,
=>Direct mapped cache
=>Number of lines in the cache = 32
=>Number of words in cache = 4 words
=>Word size = 4 bytes
=>Address = 16 bits
The answer will be "7"
Explanation:
Direct mapped cache:
Tag | Cache index | Block offset |
7 bits 5 bits 4 bits
Calculating size of line:
=>Size of line = 4 words
=>Size of line = 4*4 bytes as 1 word = 4 bytes
=>Size of line = 16 bytes
Calculating number of bits for block offset:
=>Number of bits for block offset = log2(size of line in bytes)
=>Number of bits for block offset = log2(16)
=>Number of bits for block offset = 4 bits
Caculating number of bits for cache index:
=>Number of bits for cache index = log2(number of lines)
=>Number of bits for cache index = log2(32)
=>Number of bits for cache index = 5 bits
Calculating number of bits for tag:
=>Number of bits for tag = total address bits - offset bits - cache index bits
=>Number of bits for tag = 16 bits - 4 bits - 5 bits
=>Number of bits for tag = 7 bits
I have explained each and every part with the help of statements attached to the answer above.