20Suppose a computer using set associative cache has 218 byt
20.Suppose a computer using set associative cache has 218 bytes of byte-addressable main memory and a
 cache of 128 blocks, and each cache block contains 8 bytes.If this cache is 4-way set associative, what is the
 size in bits of the tag field?.
Solution
 ============================================================
  -------------
 Answer:
 -------------
Given
    Set associative cache has 2^18 bytes of byte-addressable main memory
    Cache of 128 blocks
    Each cache block contains 8 bytes
   
   A four-way set implied 4 lines / set in the cache.
   
    ----------------------------------------------------------------
     Calculating total number of lines in the cache
    ----------------------------------------------------------------
         => Cache blocks * number of bytes in each block
        = 128 * 8
        = 1024 lines in the cache
       
   Therefore, The cache consists of 1024 lines/4 lines/set = 256 sets
    Threfore 8 bits are required to identify the set number.
   
   
    Given 2^18 bytes of byte-addressable main memory
    => 18-bit address is needed;
   Main memory consists of 2^18 byte/8 bytes = 2^15 blocks
   
    => The length of
           Tag + Set = 15
           Tag = 15-8
           Tag = 7  
          
    => Hence The length of tag field is 7 bits.
          
============================================================

