Assignment I
Problem Bank 01
Assignment Description:
The assignment aims to provide deeper understanding of cache by analysing it’s
behaviour using cache implementation of CPU- OS Simulator. The assignment has three
parts.
Part I deals with Cache Memory Management with Direct Mapping
Part II deals with Cache Memory Management with Associative Mapping
Part III deals with Cache Memory Management with Set Associative Mapping
Submission: You will have to submit this documentation file and the name of the file
should be GROUP-NUMBER.pdf. For Example, if your group number is 1, then the file
name should be GROUP-1.pdf.
Submit the assignment by 5th December 2021, through canvas only. File submitted by any
means outside CANVAS will not be accepted and marked.
Caution!!!
Assignments are designed for individual groups which may look similar and you may not
notice minor changes in the assignments. Hence, refrain from copying or sharing documents
with others. Any evidence of such practice will attract severe penalty.
Evaluation:
The assignment carries 10 marks
Grading will depend on
o Contribution of each student in the implementation of the assignment
o Plagiarism or copying will result in -10 marks
************************FILL IN THE DETAILS GIVEN BELOW**************
Assignment Set Number:
Group Name:
Contribution Table:
Contribution (This table should contain the list of all the students in the group. Clearly
mention each student’s contribution towards the assignment. Mention “No Contribution” in
cases applicable.)
Sl. Name (as appears in Canvas) ID NO Contribution
No.
Resource for Part I, II and III:
Use following link to login to “eLearn” portal.
o https://elearn.bits-pilani.ac.in
Click on “My Virtual Lab – CSIS”
Using your canvas credentials login in to Virtual lab
In “BITS Pilani” Virtual lab click on “Resources”. Click on “Computer Organization
and software systems” course.
o Use resources within “LabCapsule3: Cache Memory”
Code to be used:
The following code written in STL Language, implements searching of an element
(key) in an array using linear search technique.
program LinearSearch
var a array(50) byte
writeln("Array Elements: ")
num = 10
for n = 0 to num
a(n) = n
writeln(a(n))
next
key = 10
writeln("Key to be searched: ",key)
found = 0
for n = 0 to num
temp = a(n)
if temp = key then
found = 1
writeln("Key Found",temp)
break
end if
next
if found <> 1 then
writeln("Key Not Found")
end if
end
General procedure to convert the given STL program in to ALP :
Open CPU OS Simulator. Go to advanced tab and press compiler button
Copy the above program in Program Source window
Open Compile tab and press compile button
In Assembly Code, enter start address and press Load in Memory button
Now the assembly language program is available in CPU simulator.
Set speed of execution to FAST.
Open I/O console
To run the program press RUN button.
General Procedure to use Cache set up in CPU-OS simulator
After compiling and loading the assembly language code in CPU simulator, press
“Cache-Pipeline” tab and select cache type as “data cache”. Press “SHOW CACHE..”
button.
In the newly opened cache window, choose appropriate cache Type, cache size, set
blocks, replacement algorithm and write back policy.
Part I: Direct Mapped Cache
a) Execute the above program by setting block size = 4 and cache size = 8, 16 and 32.
Record the observation in the following table for various values of “num” in the
program.
num Block Size Cache size # Hits # Misses %Hit Ratio
10 4 8 114 72 61.29032
4 16 148 38 79.56989
4 32 160 26 86.02151
15 4 8 139 87 61.50442
4 16 173 53 76.54867
4 32 198 28 87.61062
20 4 8 164 102 61.65414
4 16
4 32
25 4 8
4 16
4 32
b) Comment on the result obtained in the above table by keeping in mind the locality of
reference.
Part II: Associative Mapped Cache
a) Execute the above program by setting block size = 4 and cache size = 8, 16 and 32.
Record the observation in the following table for various values of “num” in the
program.
LRU Replacement Algorithm
num Block Size Cache size # Hits # Misses %Hit Ratio
10 4 8 94 92 50.53763
4 16 158 28 84.94624
4 32 158 28 84.94624
15 4 8 114 112 50.44248
4 16 196 30 86.72566
4 32 196 30 86.72566
20 4 8 134 132 50.37594
4 16
4 32
25 4 8
4 16
4 32
b) Comment on the result obtained in the above table by keeping in mind the locality of
reference.
c) Compare the performance of Associative mapped cache and Direct Mapped Cache
d) Fill up the following table for three different replacement algorithms and state
which replacement algorithm is better and why ?
Replacement Algorithm : Random , num = 25
Block Size Cache size Miss Hit Hit ratio
2 4 143 163 53.26797
2 8 83 223 72.87582
2 16 73 233 76.14379
2 32 59 247 80.71895
2 64 54 252 82.35294
Replacement Algorithm : FIFO, num = 25
Block Size Cache size Miss Hit Hit ratio
2 4 146 160 52.28758
2 8 72 234 76.47059
2 16 64 242 79.08497
2 32 62 244 79.73856
2 64 54 252 82.35294
Replacement Algorithm : LRU, num = 25
Block Size Cache size Miss Hit Hit ratio
2 4 163 143 46.73203
2 8 62 244 79.73856
2 16 62 244 79.73856
2 32 60 246 80.39216
2 64 54 252 82.35294
Part III: Set Associative Mapped Cache
Execute the above program by setting the following Parameters:
Number of sets (Set Blocks ) : 2 way
Cache Type : Set Associative
Replacement: LRU/FIFO/Random
num = 25
a) Fill up the following table for three different replacement algorithms and state which
replacement algorithm is better and why ?
Replacement Algorithm : Random
Block Size Cache size Miss Hit Hit ratio
4 4
4 8
4 16
4 32
4 64
Replacement Algorithm : FIFO
Block Size Cache size Miss Hit Hit ratio
4 4
4 8
4 16
4 32
4 64
Replacement Algorithm : LRU
Block Size Cache size Miss Hit Hit ratio
4 4
4 8
4 16
4 32
4 64
b) Plot the graph of Cache Hit Ratio Vs Cache size with respect to different replacement
algorithms. Comment on the graph that is obtained.
c) Fill in the following table and analyse the behaviour of Set Associate Cache. Which one is
better and why?
Replacement Algorithm : LRU, num=20
Block Size, Set Blocks Miss Hit Hit ratio
Cache size
2, 64 2 – Way 50 216
2, 64 4 – Way 50 216
2, 64 8 – Way 51 215