Basic Cache

On a request from the processor for the data in memory address , we search the tags in cache:

  • is a tag
    1. Return data.
  • is not a tag
    1. Read data at address from memory.
    2. Return data.
    3. Select an address in the cache to hold and its data (according to replacment policy).
    4. Store in tag with data.

We use a number of approaches to organise the cache described over the next few topics, including this one.

Direct-mapped cache

Direct-mapped cache

In direct-mapped cache, each block in memory maps to a **single**, **specific** cache block.

For a direct mapped cache consisting of blocks: ?

  • Block of main memory maps to cache block .

To find out which block actually resides in a cache block at any given time we use a tag field which distinguishes one memory block from another.

A direct-mapped cache address is composed of the following: ?

  • The : number of bits required to address all cache blocks.
  • The : the number of bits required to address all words within a block.
  • The : the number of bits left over after the block and offset. Formatted as such: (, , ).
title: Remember the order: $\color{blue}\textsf{tag}$, $\color{red}\textsf{block}$, $\color{green}\textsf{word}$
Link to original

title: Example 1
![](https://git.is.horse/insert/university/obsidian-notes/-/raw/9d95afcbbdb7a4c77ca9f62b32e35c6f31e269e7/University/Year%201/Semester%201/4CCS1CS1%20Computer%20Systems%201/Week%209.%20Memory%20hierarchy%20and%20cache%20systems/Diagrams/Pasted%20image%2020211206123621.png)
title: Example 2
![](https://git.is.horse/insert/university/obsidian-notes/-/raw/9d95afcbbdb7a4c77ca9f62b32e35c6f31e269e7/University/Year%201/Semester%201/4CCS1CS1%20Computer%20Systems%201/Week%209.%20Memory%20hierarchy%20and%20cache%20systems/Diagrams/Pasted%20image%2020211206123733.png)