Tutorial/Lab #4
Problems about Cache Memory
4.2 A two-way set associative cache has lines of 16 bytes and a total size of 8 bytes. The 64-Mbyte main memory is byte-addressable. Show the format of main memory address.
Kb => 1,024
Mb => 1024 * 1024
Ans.
A two-way set => 2 lines / set in the cache;
The cache has lines of 16 bytes and a total size of 8K bytes => There are a total of 8K bytes/16 bytes = 512 lines (23*210/24) in the cache;
‘2 lines / set in the cache’ AND ‘There are a total of 512 lines in the cache’
=> The cache consists of 512 lines/2 lines/set = 256 sets
=> 8 bits (256=28) are needed to identify the set number.
64-Mbyte main memory is byte-addressable
=> There are 64M units to be addressed
=> A 26-bit (26*220) address is needed;
‘The cache has lines of 16 bytes’ AND ‘64-Mbyte main memory’
=> Main memory consists of 64-Mbyte/16 bytes = 222 blocks
=> The length of Tag + Set = 22
=> The length of Tag = 22-8 = 14;
The word field length is 26 – 22 = 4 bits
(Another way to calculate word field length:
The cache has lines of 16 bytes => The main memory block size is 16 bytes;
The main memory is byte-addressable => The word length (size) is 1 byte;
=> There are 16/1=16 words in one block;
=> 4 bits (16=24) are needed to identify the word number.)
Therefore, the format of main memory is
Tag Set Word
14
8
4
4.3 For the hexadecimal main memory address 111111, 666666, BBBBBB, show the following information, in hexadecimal format: a) Tag, Line, and Word values for a direct-mapped cache, using the format of Figure 4.8 (slide 27).
Ans. Address
(in hexadecimal format)
111111
666666
BBBBBB
Address
(in binary format)
0001 0001 0001 0001 0001 0001
0110 0110 0110 0110 0110 0110
1011 1011 1011 1011 1011 1011
Tag
0001 0001 (11h)
0110 0110 (66h)
1011 1011 (BBh)
Line
0001 0001 0001 00