When CUP searches for data in a Cache memory and if it is not found in it then this data must be transferred from main memory to cache memory. Thus the process of transferring of data between Cache Memory and Primary Memory of a computer system is known as Memory Mapping.

Memory Mapping Techniques:

Mapping of data between these two memories can be done by three different techniques and these are listed below. In each mapping techniques the CPU will use a 15 bit address to store a 12 bit data.

    1. Direct Mapping
    2. Associative Mapping
    3. Set associative Mapping

Direct Mapping:

In Direct mapping the address of CPU is dived into two fields. These two fields are Index field and Tag field. In general if there are 2k data in cache memory and 2n data in main memory or primary memory. Then k bits are used for Index field and n – k bits are used as Tag field. For example if n is 15 and k is 9 then 9 bits are used as Index field and 6 bits are used as Tag field. The CPU uses n bits address to access main memory. It uses k bits address to access cache memory. As n is divided into Index and Tag field similarly k is divide into data field and Tag field. When a data is need by CUP then a memory request is generated. Now the Tag field of CPU address is compared with Tag field of Cache address. If these two tag addresses match then it is read from the cache memory otherwise data is read from primary memory. The disadvantage of Direct mapping is that two or more data whose Index numbers are same but Tag numbers are different cannot be together in the Cache at the same time.

Associative Mapping:

In this method an associative memory is used as a cache memory. The associative memories store the data with their corresponding addresses. They permit any location to store any data from main memory. When CUP needs a data, a CPU address is placed in the argument register. Then this address is searched in associative memories. If this address is found then data is read and sent to the CPU. If it is not found then data is accessed from the main memory. If data is not found then data with its address is transferred to the associative cache memory. If it is full then a data must be displaced to create a room for the new data.

Set Associative Mapping:

We know that in Direct mapping, a Cache cannot have two or more data whose Index number are same at the same time. Thus to overcome this problem a new type of Cache is used, which is an improvement over Direct mapping  method. In Set Associative mapping, the Cache can store two data having different Tag number at same Index field. When the CPU generates a memory request then the Index value of address is used to access the Cache. The Tag field of CUP address is compared both Tags in Cache. If Tag value of CUP address is matched with any of Tags then data is sent to CUP. Otherwise CUP access the data from main memory.