Skip to content
Official PYQ · 2015

GATE CS 2015 Set 3 Q14 — Memory Hierarchy: Cache, Main Memory and Secondary Storage

Explain with AI

Consider a machine with a byte addressable main memory of 2202^{20} bytes, block size of 1616 bytes and a direct mapped cache having 2122^{12} cache lines. Let the addresses of two consecutive bytes in main memory be (E201F)16\textsf{(E201F)}_{16} and (E2020)16\textsf{(E2020)}_{16}. What are the tag and cache line addresses ( in hex) for main memory address (E201F)16\textsf{(E201F)}_{16}?

Choose one option
View worked solution

Answer: A

In a direct-mapped cache, the physical address is divided into three fields: Tag, Line Index (or Cache Line Address), and Block Offset.

1. Determine the Bit Widths

  • Physical Address Size: The main memory is 2202^{20} bytes, so the physical address is 2020 bits.
  • Block Offset: The block size is 1616 bytes (242^4 bytes), which requires log⁡2(16)=4\log_2(16) = 4 bits.
  • Line Index: The cache has 2122^{12} lines, which requires log⁡2(212)=12\log_2(2^{12}) = 12 bits.
  • Tag: Tag bits=Physical Address bits−(Line Index bits+Block Offset bits)\text{Tag bits} = \text{Physical Address bits} - (\text{Line Index bits} + \text{Block Offset bits}) Tag bits=20−(12+4)=4 bits\text{Tag bits} = 20 - (12 + 4) = 4 \text{ bits}

Thus, the 20-bit physical address format is partitioned as:

Tag Line Index Block Offset
4 bits 12 bits 4 bits

2. Analyze the Address (E201F)16\textsf{(E201F)}_{16}

Convert the hexadecimal address (E201F)16\textsf{(E201F)}_{16} into binary:

E201F16=1110⏟E0010⏟20000⏟00001⏟11111⏟F\textsf{E201F}_{16} = \underbrace{1110}_{\text{E}} \quad \underbrace{0010}_{2} \quad \underbrace{0000}_{0} \quad \underbrace{0001}_{1} \quad \underbrace{1111}_{\text{F}}

Now, split the 20-bit binary address according to our fields:

  • Tag (MSB 4 bits): 11102=E161110_2 = \textsf{E}_{16}
  • Line Index (Middle 12 bits): 0010  0000  00012=201160010 \; 0000 \; 0001_2 = \textsf{201}_{16}
  • Block Offset (LSB 4 bits): 11112=F161111_2 = \textsf{F}_{16}

Therefore, the tag is E\textsf{E} and the cache line address is 201\textsf{201}.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Memory Hierarchy: Cache, Main Memory and Secondary Storage questions