Direct-mapped cache conflicts
Cache Memory

Answer & solution
Official answer: A, B
Givens and goal
A byte-addressed machine has 16 MB physical memory and an initially empty 4 KB direct-mapped cache with 16-byte blocks. Repeat P,Q,R,S ten times, where P=0x845B32, Q=0x845B26, R=0x845B36, S=0x846B32. Select: A every P misses; B every R hits; C every Q misses; D all S after the first hit. K=2¹⁰,M=2²⁰.
Approach
Split addresses into tag, line index, and byte offset before tracing the repeating pattern.
Step-by-step solution
1. There are 4096/16=256 cache lines, requiring 8 index bits, and a 16-byte block requires 4 offset bits. In a 24-bit physical address, the remaining 12 bits form the tag.
2. The decompositions (tag,index,offset) are P=(845,B3,2), Q=(845,B2,6), R=(845,B3,6), S=(846,B3,2), all hexadecimal. P and R share one memory block; S has the same index but a different tag; Q has a separate index.
3. In the first cycle, P misses and loads tag 845 into line B3. Q misses and loads its separate line B2. R hits the block loaded by P. S misses and replaces B3 with tag 846.
4. At the start of every later cycle B3 contains S’s tag. P therefore misses and replaces S; R subsequently hits P’s block; S then misses and replaces P again. Q remains resident and hits in all nine later cycles.
5. A and B are true; C and D are false. As a check, misses total 10 for P, 1 for Q, 0 for R, and 10 for S: 21 misses and 19 hits over 40 accesses. Spatial locality explains R’s hits, whereas index conflict explains repeated P/S misses.
