Lecture-6.3: Direct Mapping Math Problem Solution, Part-3 (COA)

 Practice Problems Based on Direct Mapping

Question-04: Consider a direct mapped cache of size 32 KB with block size 32 bytes. The CPU generates 32-bit addresses. The number of bits needed for cache indexing and the number of tag bits are respectively-

1)     10, 17

2)     10, 22

3)     15, 17

4)     5, 17

 

Solution:

Given-

Cache memory size = 32 KB

Block size = Frame size = Line size = 32 bytes

Number of bits in physical address = 32 bits

Number of Bits in Block Offset-

We have,

Block size

= 32 bytes

= 25 bytes

Thus, Number of bits in block offset = 5 bits



Number of Bits in Line Number-

Total number of lines in cache

= Cache size / Line size

= 32 KB / 32 bytes

= 210 lines

Thus, Number of bits in line number = 10 bits

 

Number of Bits Required for Cache Indexing-

Number of bits required for cache indexing

= Number of bits in line number

= 10 bits

 

Number Of Bits in Tag-

Number of bits in tag

= Number of bits in physical address – (Number of bits in line number + Number of bits in block offset)

= 32 bits – (10 bits + 5 bits)

= 32 bits – 15 bits

= 17 bits

Thus, Number of bits in tag = 17 bits




Thus, Option (A) is correct.


Question-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

Number of Bits in Physical Address-

We have,

Size of main memory

= 232 bytes

Thus, Number of bits in physical address = 32 bits


Number of Bits in Block Offset-

We have,

Block size

= 32 bytes

= 25 bytes

Thus, Number of bits in block offset = 5 bits


Number of Bits in Line Number-

Total number of lines in cache

= 512 lines

= 29 lines

Thus, Number of bits in line number = 9 bits


Number Of Bits in Tag-

Number of bits in tag

= Number of bits in physical address – (Number of bits in line number + Number of bits in block offset)

= 32 bits – (9 bits + 5 bits)

= 32 bits – 14 bits

= 18 bits

Thus, Number of bits in tag = 18 bits



Post a Comment

0 Comments