user2336315
user2336315

Reputation: 16067

Cache and memory

First of all, this is not language tag spam, but this question not specific to one language in particulary and I think that this stackexchange site is the most appropriated for my question.

I'm working on cache and memory, trying to understand how it works. What I don't understand is this sentence (in bold, not in the picture) :

In the MIPS architecture, since words are aligned to multiples of four bytes, the least significant two bits are ignored when selecting a word in the block.

So let's say I have this two adresses :

    [1........0]10
    [1........0]00
         ^
         |
   same 30 bits for boths [31-12] for the tag and [11-2] for the index (see figure below)

As I understand the first one will result in a MISS (I assume that the initial cache is empty). So one slot in the cache will be filled with the data located in this memory adress.

Now, we took the second one, since it has the same 30 bits, it will result in a HIT in the cache because we access the same slot (because of the same 10 bits) and the 20 bits of the adress are equals to the 20 bits stored in the Tag field.

So in result, we'll have the data located at the memory [1........0]10 and not [1........0]00 which is wrong !

So I assume this has to do with the sentence I quote above. Can anyone explain me why my reasoning is wrong ?

The cache in figure :

enter image description here

Upvotes: 2

Views: 3851

Answers (1)

user2336315
user2336315

Reputation: 16067

In the MIPS architecture, since words are aligned to multiples of four bytes, the least significant two bits are ignored when selecting a word in the block.

It just mean that in memory, my words are aligned like that :

enter image description here

So when selecting a word, I shouldn't care about the two last bits, because I'll load a word.

This two last bits will be useful for the processor when a load byte (lb) instruction will be performed, to correctly shift the data to get the one at the correct byte position.

Upvotes: 1

Related Questions