Introduction
Cache Basics Direct Mapped Cache Direct Mapped Example 1 Direct Mapped Example 2 Direct Mapped Problem 1 Direct Mapped Problem 2 Direct Mapped Problem 3 Direct Mapped Problem 4 Direct Mapped Comparators Direct Mapped Disadvantages Direct Mapped Locality Direct Mapped UVM Example Associative Mapped Cache Associative Mapped Problem 1 Associative Mapped Problem 2 Associative Mapped Problem 3 Associative Mapped Problem 4 Set Associative Mapped Cache Set Associative Mapped Comparators Set Associative Mapped Problem 1 Set Associative Mapped Problem 2 Set Associative Mapped Problem 3 Set Associative Mapped Problem 4 Set Associative Mapped Problem 5 Other Mapping Problem - Example 1 Cache Replacement Algorithms LRU Cache Replacement Algorithm FIFO Cache Replacement Algorithm MRU Cache Replacement Algorithm PLRU Cache Replacement Algorithm Round Robin Cache Replacement AlgorithmUVMArena
Direct Mapped Cache – Example 1
1. Logical Address Generation
The CPU first generates a logical address. A logical address consists of two fields:
- Page Number
- Page Offset
Example assumptions:
- Process P1 has 4 pages
- Each page contains 4 bytes
To represent 4 pages we need 2 bits:
| Binary | Page Number |
|---|---|
| 00 | Page 0 |
| 01 | Page 1 |
| 10 | Page 2 |
| 11 | Page 3 |
Each page has 4 bytes, so the offset also needs 2 bits.
2. Example Logical Address
Assume the CPU requests:
- Page 2
- Byte 1
Binary values:
| Field | Binary |
|---|---|
| Page Number | 10 |
| Offset | 01 |
Logical Address = 10 01
3. Logical Address → Physical Address
The logical address is converted into a physical address using the page table.
- CPU uses the Page Table Base Register
- Finds the entry for the requested page
- The entry contains the frame number
Assume:
- Total frames in RAM = 8
- So frame number requires 3 bits
| Frame | Binary |
|---|---|
| 5 | 101 |
Page 2 is stored in Frame 5.
Physical Address
Frame Number | Offset 101 | 01
4. Accessing RAM
When accessing RAM, the physical address is interpreted as:
Frame Number + Frame OffsetSteps:
- Use frame number to locate the frame.
- Use offset to locate the exact byte.
5. Cache Memory Organization
Assume cache has 4 lines.
To address 4 cache lines we need 2 bits.
| Binary | Line |
|---|---|
| 00 | Line 0 |
| 01 | Line 1 |
| 10 | Line 2 |
| 11 | Line 3 |
6. Address Format for Cache
When accessing cache memory, the physical address is divided into:
Tag | Line Number | Offset
Example using frame number 101:
Tag = 1 Line Number = 01 Offset = 01
The CPU goes directly to Line 1 in the cache.
7. Why Tag is Needed
Multiple frames can map to the same cache line.
Example mapping:
| Frame | Cache Line |
|---|---|
| 1 | Line 1 |
| 5 | Line 1 |
Because both frames map to the same line, the cache stores a tag to identify which frame is currently stored.
- Tag = 0 → Frame 1
- Tag = 1 → Frame 5
8. Cache Access Process
- CPU generates logical address.
- Logical address is converted to physical address.
- Physical address is split into tag, line number, offset.
- CPU goes directly to the specified cache line.
- Compare the stored tag with requested tag.
If tags match → Cache Hit
If tags do not match → Cache Miss → Access RAM