Direct Mapping Problems
Direct Mapping Problems
In direct mapping,
A particular block of main memory can map only to a particular line of the cache.
The line number of cache to which a particular block can map is given by-
Cache line number = ( Main Memory Block Address ) Modulo (Number of lines in Cache)
of main memory can map to line number (j mod n) only of the cache.
Example
Consider cache memory is divided into ‘n’ number of lines.
Then, block ‘j’ of main memory can map to line number (j mod n) only of the cache.
Solution-
Given-
Cache memory size = 16 KB
Block size = Frame size = Line size = 256 bytes
Main memory size = 128 KB
Problem-02:
Consider a direct mapped cache of size 512 KB with block size 1 KB. There are 7
bits in the tag. Find-
1. Size of main memory
2. Tag directory size
Solution-
Given-
Cache memory size = 512 KB
Block size = Frame size = Line size = 1 KB
Number of bits in tag = 7 bits
We consider that the memory is byte addressable.
Problem-03:
Consider a direct mapped cache with block size 4 KB. The size of main memory is
16 GB and there are 10 bits in the tag. Find-
1. Size of cache memory
2. Tag directory size
Solution-
Given-
Block size = Frame size = Line size = 4 KB
Size of main memory = 16 GB
Number of bits in tag = 10 bits
We consider that the memory is byte addressable.
Solution-
Given-
Cache memory size = 32 KB
Block size = Frame size = Line size = 32 bytes
Number of bits in physical address = 32 bits
Problem-05:
Consider a machine with a byte addressable main memory of 232 bytes divided into
blocks of size 32 bytes. Assume that a direct mapped cache having 512 cache lines
is used with this machine. The size of the tag field in bits is ______.
Solution-
Given-
Main memory size = 232 bytes
Block size = Frame size = Line size = 32 bytes
Number of lines in cache = 512 lines
Solution-
Given-
Cache memory size = 8 KB
Block size = Frame size = Line size = 32 bytes
Number of bits in physical address = 32 bits