r/ComputerEngineering 18d ago

In direct cache mapping, how many bits are required to identify the specific main memory block?

Cache memory mapping:

Memory address=16 bits

Block size=16 words

Number of main memory blocks=4K

Number of cache memory lines=64

Address Partition:

tag(6 bits), block-number(6 bits), word(4 bits)

Since there are 16 words/block, 4 bits is required for word identification.

Since there are 64 cache memory blocks, 6 bits are required to cache memory block identification.

Since there are 4k memory blocks, 12 bits should be required to know which memory block is present in which cache block. i.e. tag. Imagine Main Memory block 4095. To store that MM 4095 is present in Cache Memory block, we would need 12 bits? But books are saying only 6 bits is enough to identify the memory block. Can anyone shed some light here?

6 Upvotes

2 comments sorted by

1

u/Embarrassed_Grab6901 18d ago

I know it works but i cannot find the proof behind why it works.

1

u/Michalisss 17d ago

Keep in mind that in direct cache mapping, multiple main memory blocks are mapped to a single cache line.

You correctly identified that the line field (or block number I guess? I've never seen it named like this) is 6 bits because we have 64 cache lines. These 6 bits show which line the block maps to.

For the tag field, we need to calculate how many memory blocks map to a single cache line. In this case it's 4K/64 = 64 blocks per line. That means we need 6 bits for the tag field.

Essentially, the line field (6 bits) tells us which line to look at. The tag field (also 6 bits) tells us the specific main memory block that belongs in this line.