My question is, how can I get the line number just by dividing the number by the cache line size(64)?
For example, let's take 510,
510 in binary is 000000000(00111)111110 , so 00111 is show the line and 7 ,But it can be get easily by 510/64=7 ,How it can happen ,becasue the address contain all the information other than line like tag,offset.What is the idea behind it, and does it always work?
-
$\begingroup$ What about 4650? $\endgroup$greybeard– greybeard2025年11月18日 13:26:32 +00:00Commented 7 hours ago
1 Answer 1
Since cache block (also called cache line) size is given as 64 byte and the system is assumed to be byte addressable, the first 64 bytes of main memory (RAM) will go in first cache block (index 0) i.e. memory cells at 0, 1, 2 .... 63 will go in cache block 0.
Then memory cells 64, 65, 66 .... 127 will go in the cache block 1.
Do you see a pattern?
The pattern is that the cache $$ \text{Cache Block No.} = \left\lfloor \frac{A}{B} \right\rfloor $$
Where:
- (A) = memory address (in decimal form) of memory cells
- (B) = cache block size
Note that memory address is assumed to be in decimal form. This formula wont work for case when address is given in other form eg binary or hexadecimal form.
-
$\begingroup$ What about 4650? $\endgroup$greybeard– greybeard2025年11月18日 13:30:40 +00:00Commented 7 hours ago
Explore related questions
See similar questions with these tags.