Direct Mapping — Map cache and main memory

Danoja Dias
Break the Loop
Published in
3 min readMay 8, 2017

--

In the previous article, I explained you about what is cache memory. Let’s see how cache memory maps with the main memory.

First we conceptually divide the memory into blocks. Cache is also divided into lines. Note that these are conceptual things and they are not divided in physically. Following diagram shows how it is divided conceptually.

How cache and main memory is conceptually divided

Here is how we divide the main memory into blocks and the size of a block is equal to the size of the cache line. In memory smallest addressable unit is called as word. It can be several Bytes but for the sake of the simplicity, I’ll take it a word equals to one Byte.

1 word = 1 byte (for this example)

So that rest of this article uses the word instead of byte.

Let’s see the main memory. Let’s assume that Cache is 16 words in size and Main memory is 64 words in size. If a block contains the 4 words then number of blocks in the main memory can be calculated like following.

Number of blocks in the main memory = 64/4 = 16blocks.

That means we have 16 blocks in the main memory and each block has four words in it. This is shown in the following diagram.

--

--

Danoja Dias
Break the Loop

ATL at Enactor Ltd | Former R&D Engineer at Synopsys Inc | Former Intern at WSO2 | BSc Computer Engineering | GSoC2016 | http://linkedin.com/in/danojadias