0% found this document useful (0 votes)
20 views5 pages

Test-6-PracticeQuestion-cachememory-2 - Cache Mappping

The document contains four practice problems about cache mapping. Each problem provides parameters like main memory size, cache capacity, block size and memory addresses accessed. It then shows the calculations to determine hit ratio, final cache state and number of block replacements.

Uploaded by

anik.additional
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Test-6-PracticeQuestion-cachememory-2 - Cache Mappping

The document contains four practice problems about cache mapping. Each problem provides parameters like main memory size, cache capacity, block size and memory addresses accessed. It then shows the calculations to determine hit ratio, final cache state and number of block replacements.

Uploaded by

anik.additional
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practice problems: Cache Mapping

1. Assume a Computer design problem having following parameters:


Main memory: 16MB, Byte addressable, and Block size: 16 Bytes
Cache capacity: 1KB, Direct mapped,
A Computer program accesses (in order) memory locations:
33, 65, 97, 2080, 4160, 1121, 34, 4161, 98
(i) Calculate the hit ratio?
(ii) Show the state of cache at the end.
(iii) How many blocks are replaced?
Assume that the cache is empty at the beginning.
You need to show the calculations.
Solution
Block size = 16 Bytes
Number of lines in cache: 1024 Bytes/ 16 Bytes = 64
Line no
CPU accesses
Block of RAM Checked
Memory Hit/
j= (to be assigned in Consequences State of cache
address in Miss
quotient(Address/16) case of Miss)
order
i = j mod 64
33 2 2 M Block-2 to be copied into line-2 Cache
65 4 4 M Block-4 to be copied into line-4 Line-0
97 6 6 M Block-6 to be copied into line-6 Line-1
2080 130 2 M Block-130 to be copied into line-2 Line-2 Block-2 (RAM) (replaced)
Block-2 is replaced Block-130
4160 260 4 M Block-260 to be copied into line-4 Line-3
Block-4 is replaced Line-4 Block-4 (RAM)
1121 70 6 M Block-70 to be copied into line-6 Line-5
Block-6 is replaced Line-6
34 2 2 M Block-2 to be copied into line-2
Block-130 is replaced Hit Ratio = (1/9) x100%
4161 260 4 H Reads from Line-4 Number of blocks replaced = 5
98 6 6 M Block-6 to be copied into line-6
Block-70 is replaced

Solution ends
2. Assume a Computer design problem having following parameters:
Main memory: 4MB, Byte addressable, and Block size: 16 Bytes
Cache capacity: 2KB, Direct mapped,
A Computer program accesses (in order) memory locations: 49, 65, 97, 4144, 4160, 4192, 48, 65, 98.
(i) Calculate the hit ratio?
(ii) Show the state of cache at the end.
(iii) How many blocks are replaced?
Assume that the cache is empty at the beginning.
Solution
Block size = 16 Bytes
Number of lines in cache: 2x1024 Bytes/ 16 Bytes = 128
Line no
CPU accesses Checked
Block of RAM Hit/
Memory (to be assigned in Consequences State of cache
j = Address/16 Miss
address in order case of Miss)
i = j mod 128
49 3 3 M Block-3 to be copied into line-3
65 4 4 M Block-4 to be copied into line-4
97 6 6 M Block-6 to be copied into line-6 Line-0
4144 259 3 M Block-259 to be copied into line-3 Line-1
Block-3 is replaced Line-2
4160 260 4 M Block-260 to be copied into line-4 Line-3 Block-3 Block-259 Block-3
Block-4 is replaced Line-4 Block-4 Block-260 Block-4
4192 262 6 M Block-262 to be copied into line-6 Line-5
Block-6 is replaced Line-6 Block-6 Block-262 Block-6
48 3 3 M Block-3 to be copied into line-3
Block-259 is replaced Line-14
65 4 4 M Block-4 to be copied into line-4
Block-260 is replaced Hit Ratio = 0%
98 6 6 M Block-4 to be copied into line-6 Number of blocked replaced = 6
Block-262 is replaced

Solution ends
3. Assume a Computer design problem having following parameters:
Main memory: 1MB, Byte addressable, and Block size: 8 Bytes
Cache capacity: 1KB, Direct mapped,

A Computer program accesses (in order) memory locations: 25, 33, 50, 26, 34, 51, 1048, 1056 and 2096.
(i) Calculate the hit ratio?
(ii) Show the state of cache at the end.
(iii) How many blocks are replaced?
Assume that the cache is empty at the beginning.
Solution
Block size = 8 Bytes
Number of lines in cache: 1024 Bytes/ 8 Bytes = 128

Line no
CPU accesses Checked
Block of RAM Hit/
Memory (to be assigned in Consequences State of cache
j = Address/8 Miss
address in order case of Miss)
i = j mod 128
25 3 3 M Block-3 to be copied into line-3
33 4 4 M Block-4 to be copied into line-4
50 6 6 M Block-6 to be copied into line-6 Line-0
26 3 3 H Reads from Line-3 Line-1
34 4 4 H Reads from Line-4 Line-2
51 6 6 H Reads from Line-6 Line-3 Block-3 Block-131
1048 131 3 M Block-131 to be copied into line-3 Line-4 Block-4 Block-132
Block-3 is replaced Line-5
1056 132 4 M Block-132 to be copied into line-4 Line-6 Block-6 Block-262
Block-4 is replaced
2096 262 6 M Block-262 to be copied into line-6
Block-6 is replaced
Hit Ratio = (3/9) x 100 =
Number of blocked replaced = 3

Solution ends
4. Assume a Computer design problem having following parameters:
Main memory: 4MB, Byte addressable, and Block size: 16 Bytes
Cache capacity: 2KB, Direct mapped,
A Computer program accesses (in order) memory locations: 49, 65, 97, 4144, 4160, 4192, 48, 65, 98.
(i) Calculate the hit ratio?
(ii) Show the state of cache at the end.
(iii) How many blocks are replaced?
Assume that the cache is empty at the beginning.
Solution
Block size = 16 Bytes
Number of lines in cache: 2x1024 Bytes/ 16 Bytes = 128
Line no
CPU accesses Checked
Block of RAM Hit/
Memory (to be assigned in Consequences State of cache
j = Address/16 Miss
address in order case of Miss)
i = j mod 128
49 3 3 M Block-3 to be copied into line-3
65 4 4 M Block-4 to be copied into line-4
97 6 6 M Block-6 to be copied into line-6 Line-0
4144 259 3 M Block-259 to be copied into line-3 Line-1
Block-3 is replaced Line-2
4160 260 4 M Block-260 to be copied into line-4 Line-3 Block-3 Block-259 Block-3
Block-4 is replaced Line-4 Block-4 Block-260 Block-4
4192 262 6 M Block-262 to be copied into line-6 Line-5
Block-6 is replaced Line-6 Block-6 Block-262 Block-6
48 3 3 M Block-3 to be copied into line-3
Block-259 is replaced Line-14
65 4 4 M Block-4 to be copied into line-4
Block-260 is replaced Hit Ratio = 0%
98 6 6 M Block-4 to be copied into line-6 Number of blocked replaced = 6
Block-262 is replaced

Solution ends
5. Assume a Computer design problem having following parameters:
Main memory: 16MB, Byte addressable, and Block size: 16 Bytes
Cache capacity: 1KB, Direct mapped,
A Computer program accesses (in order) memory locations:
33, 65, 97, 2080, 4160, 1121, 34, 4161, 98
(i) Calculate the hit ratio?
(ii) Show the state of cache at the end.
(iii) How many blocks are replaced?
Assume that the cache is empty at the beginning.
You need to show the calculations.
Solution
Block size = 16 Bytes
Number of lines in cache: 1024 Bytes/ 16 Bytes = 64
Line no
CPU accesses Checked
Block of RAM Hit/
Memory (to be assigned in Consequences State of cache
j = Address/16 Miss
address in order case of Miss)
i = j mod 64
33 2 2 M Block-2 to be copied into line-2
65 4 4 M Block-4 to be copied into line-4 Line-0
97 6 6 M Block-6 to be copied into line-6 Line-1
2080 130 2 M Block-130 to be copied into line-2 Line-2 Block-2 Block-130 Block-2
Block-2 is replaced Line-3 Block-3
4160 260 4 M Block-260 to be copied into line-4 Line-4 Block-4 Block-260
Block-4 is replaced Line-5
1121 70 6 M Block-70 to be copied into line-6 Line-6 Block-6 Block-70 Block-6
Block-6 is replaced
34 2 2 M Block-2 to be copied into line-2 Hit Ratio = (1/9) x100%
Block-130 is replaced Number of blocked replaced = 5
4161 260 4 H Reads from Line-4
98 6 6 M Block-6 to be copied into line-6
Block-70 is replaced

Solution ends
What do you understand by mapping technique of cache memory?
What is direct mapping? Briefly explain.
What happens when the cache is full and there is a cache miss?

You might also like