What Is Direct Mapping in Cache Memory?

TL;DR
Direct mapping is a cache memory technique that assigns each block from the main memory to a specific cache line using the formula K mod N, where K is the block number and N is the number of cache lines. This method efficiently determines which block to load into cache, optimizing access time for the CPU. Cache hits occur when the requested data is available, while misses require loading data from main memory.
Transcript
Hello friends, welcome to Gate Smashers In today's video we are going to discuss Direct Mapping As in last video we discussed about cache Mapping How many ways we can do mapping Either it is Direct, Fully Associative or K-way Set Associative So in this video we are going to talk about Direct Mapping And in this video I am going to discuss a... Read More
Key Insights
- 🫥 Direct mapping is a cache mapping technique that assigns each block of the main memory to a specific line in the cache based on the formula K mod N.
- 🚫 The main memory is divided into fixed-size blocks, with this example using 4 words per block, and the cache is divided into lines to accommodate the blocks.
- 🚫 CPU generates physical addresses to access specific words in the main memory, and the address is divided into block number and block offset.
- 🎁 Cache hit occurs when the requested block or word is already present in the cache, while cache miss occurs when it is not present, requiring replacement.
Install to Summarize YouTube Videos and Get Transcripts
Explore YouTube Video Summarizer or Get YouTube Transcript Extractor
Questions & Answers
Q: What is direct mapping in computer architecture?
Direct mapping is a cache-mapping method in which every main-memory block has one fixed cache line. The destination line is calculated with K mod N, where K is the block number and N is the number of cache lines.
Q: How are main memory blocks calculated in the example?
The main memory contains 128 words, and each block holds four words. Dividing 128 by four gives 32 blocks, numbered from block 0 through block 31.
Q: How many cache lines are used in the example?
The cache contains 16 words, and each line holds four words—the same size as a memory block. Therefore, the cache has four lines, numbered 0 through 3.
Q: How does the K mod N direct-mapping formula work?
K is the main-memory block number, and N is the number of cache lines. With four lines, block 0 maps to line 0, block 1 to line 1, block 2 to line 2, block 3 to line 3, and block 4 returns to line 0.
Q: Can a memory block be placed in any empty cache line?
No. Its destination is fixed by the K mod N formula, even when another cache line is empty. For example, block 0 cannot be placed in line 3; it maps only to line 0.
Q: How is the seven-bit physical address divided?
A 128-word memory requires seven address bits because its addresses run from 0 to 127. Since each block contains four words, two bits specify the block offset, while the remaining five bits specify one of the 32 blocks.
Q: How does the CPU locate word 10 in the example?
The seven-bit address is split into a five-bit block number and a two-bit block offset. For word 10, the block-number portion identifies block 2, and the offset identifies position 2 within that block, where numbering begins at 0.
Q: What is the difference between a cache hit and a cache miss in direct mapping?
A cache hit occurs when the requested block or word is already present in the cache. A cache miss occurs when it is absent, so the required block must replace the block occupying its fixed cache line.
Summary & Key Takeaways
-
Direct mapping is a cache mapping technique that involves dividing the main memory into fixed-size blocks and mapping them to specific lines in the cache.
-
The size of the main memory is 128 words, with 4 words per block, resulting in a total of 32 blocks.
-
CPU generates addresses for accessing specific words in the memory and can determine the corresponding line and block offset using the direct mapping formula.
Read in Other Languages (beta)
Share This Summary 📚
Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator
Explore More Summaries from Gate Smashers 📚






Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator