Consider a computer with a 4-way set-associative cache with these characteristics: Main memory size = 1 MB Word size = 1 byte Block size = 128 words Cache size = 8 KB For memory address 0C795H, find the TAG field value. Find the number of bits in TAG, SET, and WORD fields. Enter the TAG value in hexadecimal (without trailing H).
Consider a computer with a 4-way set-associative cache with these characteristics:
- Main memory size = 1 MB
- Word size = 1 byte
- Block size = 128 words
- Cache size = 8 KB
- For memory address
0C795H, find the TAG field value. - Find the number of bits in TAG, SET, and WORD fields.
Enter the TAG value in hexadecimal (without trailing H).
Answer
18
Theory
Address bits = log₂(1 MB) = log₂(2²⁰) = 20 bits. For block size 128 words (1 byte each), block/word offset bits = log₂(128) = 7 bits. Cache lines = 8 KB / 128 B = 2¹³ / 2⁷ = 2⁶ = 64 lines. In a 4-way set-associative cache, number of sets = 64 / 4 = 16 sets, so set bits = log₂(16) = 4 bits. TAG bits = 20 − (4 + 7) = 9 bits.
Solution
Step 1: Find field sizes
| Field | Computation | Bits |
|---|---|---|
| WORD (offset) | log₂(128) | 7 |
| SET (index) | 64 lines / 4 ways = 16 sets, log₂(16) | 4 |
| TAG | 20 − (7 + 4) | 9 |
Step 2: Convert address0C795H = 0000 1100 0111 1001 0101 (20 bits)
Step 3: Split as TAG | SET | WORD = 9 | 4 | 7 bits
| TAG (9) | SET (4) | WORD (7) |
|---|---|---|
| 000011000 | 1111 | 0010101 |
TAG = 000011000₂ = 0x018 ⇒ required TAG value = 18.
Also, bit counts are TAG = 9, SET = 4, WORD = 7.