The problem with the associative cache memory:
We need to use a lot of compare circuits to make a associative cache
The associative cache can store (4 bytes) data from any memory location in any slot: (= flexible)
We will trade this flexibility for remove the need for millions of compare circuits !
Inflexible caching: the data from memory can only be stored in one specific slot in the cache
With an 8-slots cache: data from address 0 must be stored in slot 0, data from address 4 must be stored in slot 1 (4/4=1), data from address 8 must be stored in slot 2 (8/4=2), etc
Inflexible caching: data from memory can only be stored in one specific slot in the cache
With an 8-slots cache: data from address 32 (32/4=8=8+0) must be stored in slot 0, data from address 36 must be stored in slot 1, data from address 40 must be stored in slot 2 (40/4=10=8+2), etc
The slot k in direct mapped cache can only store the memory addresses that are mapped to k:
The mapping is k = ((Mem Addr)/4) % CacheSize
Example: memory locations that are mapped to slot 2 in an 8-slot direct mapped cache: (part 1)
The mapping is 2 = ((Mem Addr)/4) % 8 --- = addresses 8,9,10,11 ((addr/4)%8=2)
Example: memory locations that are mapped to slot 2 in an 8-slot direct mapped cache: (part 2 + end)
The mapping is 2 = ((Mem Addr)/4) % 8 --- and address 40,41,42,43 ((addr/4)%8=2), etc,etc
We map memory addresses to block numbers in a direct mapped cache as follows:
Block number = (mem addr/4) / CacheSize
Example: when memory data from address 8,9,10,11 is stored in slot 2: we store blk num = 0
The block number stored in the slot = ({8,9,10,11}/4) / 8 = 2/8 = 0
Example: when memory data from address 40,41,42,43 is stored in slot 2: we store blk num = 1
The block number stored in the slot = ({40,41,42,43}/4) / 8 = 10/8 = 1
Practice example 1:
Find the memory locations that is currently cached in the entry 2
Answer 1:
The data is at "position 2" in block 0 in memory.
Practice example 2:
Find the memory locations that is currently cached in the entry 6
Answer 2:
The data is at "position (offset) 6" in block 2 in memory.
Practice example 3:
Find the memory locations that is currently cached in the entry 3
Answer 3:
This slot currently is not used !!