GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 42 - GeeksforGeeks

26 Dec, 2019
A computer system uses 16-bit memory addresses. It has a 2K-byte cache organized in a direct-mapped manner with 64 bytes per cache block. Assume that the size of each memory word is 1 byte.
When a program is executed, the processor reads data sequentially from the following word addresses:
128, 144, 2176, 2180, 128, 2176 
All the above addresses are shown in decimal values. Assume that the cache is initially empty. The cache hits ratio occur for for above given addresses is __________ .(A) 0.333(B) 0.666(C) 0.353(D) 0.535Answer: (A)Explanation: First, find word, block and tag size:Block size = 64 bytes = 26 bytes = 26 words (since 1 word = 1 byte)Therefore, Number of bits in the Word field = 6
Cache size = 2K-byte = 211 bytesNumber of cache blocks = Cache size / Block size = 211/26 = 25Therefore, Number of bits in the Block field = 5Total number of address bits = 16Therefore, Number of bits in the Tag field = 16 – 6 – 5 = 5For a given 16-bit address, the 5 most significant bits, represent the Tag, the next 5 bits represent the Block, and the 6 least significant bits represent the Word.
Now, check cache hit or miss for given addresses:The cache is initially empty. Therefore, all the cache blocks are invalid.
Access # 2:Address = (144)10 = (0000000010010000)2For this address, Tag = 00000, Block = 00010, Word = 010000Since tag field for cache block 00010 is 00000 before this access, this will be a cache hit (becauseaddress tag = block tag)
Access # 3:Address = (2176)10 = (0000100010000000)2For this address, Tag = 00001, Block = 00010, Word = 000000Since tag field for cache block 00010 is 00000 before this access, this will be a cache miss(address tag ≠ block tag)After this access, Tag field for cache block 00010 is set to 00001
Access # 4:Address = (2180)10 = (0000100010000100)2For this address, Tag = 00001, Block = 00010, Word = 000100Since tag field for cache block 00010 is 00001 before this access, this will be a cache hit (addresstag = block tag)
Access # 5:Address = (128)10 = (0000000010000000)2For this address, Tag = 00000, Block = 00010, Word = 000000Since tag field for cache block 00010 is 00001 before this access, this will be a cache miss(address tag ≠ block tag)After this access, Tag field for cache block 00010 is set to 00000
Access # 6:Address = (2176)10 = (0000100010000000)2For this address, Tag = 00001, Block = 00010, Word = 000000Since tag field for cache block 00010 is 00001 before this access, this will be a cache miss(address tag ≠ block tag)After this access, Tag field for cache block 00010 is set to 00001
Therefore, cache hit rate = Number of hits / Number of accesses = 2/6 = 0.333.
Option (A) is true.Quiz of this Question
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | Gate IT 2007 | Question 25
GATE | GATE-CS-2000 | Question 41
GATE | GATE-CS-2001 | Question 39
GATE | GATE-CS-2005 | Question 6
GATE | GATE MOCK 2017 | Question 21
GATE | GATE-CS-2006 | Question 47
GATE | GATE MOCK 2017 | Question 24
GATE | Gate IT 2008 | Question 43
GATE | GATE-CS-2009 | Question 38
GATE | GATE-CS-2003 | Question 90