Exemple #1
0
 /// <summary>
 /// initialize the algorithm related porperties
 /// </summary>
 public void OnCacheAlgorithimStart()
 {
     Offset           = "";
     Index            = "";
     Tag              = "";
     VisibiltyStatues = true;
     CacheBlocksPresented.Clear();
     Demonstrations.Clear();
 }
Exemple #2
0
        /// <summary>
        /// this value is used to give the tag,index and offset the correct value then convert the index value to decimal and prepair the values of the listview to be printed
        /// </summary>
        /// <param name="address"></param>
        /// <param name="numberOfBlocksOrSets"></param>
        /// <param name="blockSizeValue"></param>
        /// <param name="numberOfIndexBits"></param>
        /// <param name="numberOfTagBits"></param>
        /// <param name="cacheSizeValue"></param>
        public void BinaryToDecimal_TagIndexOffsetAssignmentnFunction(string address, int numberOfBlocksOrSets, int blockSizeValue, int numberOfIndexBits, int numberOfTagBits, int cacheSizeValue)
        {
            Tag            = address.Substring(address.Length - GetLogValue(blockSizeValue) - numberOfIndexBits - numberOfTagBits, numberOfTagBits);
            Index          = address.Substring(address.Length - GetLogValue(blockSizeValue) - numberOfIndexBits, numberOfIndexBits);
            Offset         = address.Substring(address.Length - GetLogValue(blockSizeValue), GetLogValue(blockSizeValue));
            IndexInDecimal = 0;
            int x = 0;

            for (int i = Index.Length - 1; i >= 0; i--, x++)
            {
                if (Index[i] == '1')
                {
                    IndexInDecimal += (int)Math.Pow(2, x);
                }
            }
            #region Cache Blocks Values
            for (int i = 0; i < numberOfBlocksOrSets; i++)
            {
                string BlockRow = i.ToString() + ", " + (i + numberOfBlocksOrSets).ToString() + ", " + (i + numberOfBlocksOrSets * 2).ToString() + ", " + (i + numberOfBlocksOrSets * 3).ToString() + ", " + (i + numberOfBlocksOrSets * 4).ToString() + ", " + (i + numberOfBlocksOrSets * 5).ToString() + " ," + (i + numberOfBlocksOrSets * 6).ToString() + ".......";
                if (i == IndexInDecimal)
                {
                    CacheBlocksPresented.Add(new PresentationModel(i, BlockRow, true));
                }
                else
                {
                    CacheBlocksPresented.Add(new PresentationModel(i, BlockRow, false));
                }
            }
            #endregion

            #region Cache Algorithm Explanations
            Demonstrations.Add("the Tag Bits are compared with the corresponding Tag Bits in the Cache Directory.");
            Demonstrations.Add("the Index Bits are used to select a particular Set in the Cache.");
            Demonstrations.Add("the Offest Bits are used to select a particular byte in the accessed block.");
            Demonstrations.Add("Memory Size= " + SelectedRamSize + " =2 to the power of " + TotalNumberOfBits);
            Demonstrations.Add("Cache Size= " + SelectedCacheSize + " =2 to the power of " + GetLogValue(cacheSizeValue));
            Demonstrations.Add("Block Size= " + SelectedBlockSize + " =2 to the power of " + GetLogValue(blockSizeValue));
            Demonstrations.Add("Number of bits in Tag = Total bits - Index bits - Offset bits= " + TotalNumberOfBits + "- " + GetLogValue(numberOfBlocksOrSets) + "- " + GetLogValue(blockSizeValue) + "= " + numberOfTagBits);
            if (IsDirectMapping)
            {
                Demonstrations.Add("Number of blocks in cache=" + SelectedCacheSize + "/" + SelectedBlockSize + " = (2 to the power of" + GetLogValue(cacheSizeValue) + ")/(2 to the power of " + GetLogValue(blockSizeValue) + ")= ");
                Demonstrations.Add(Math.Pow(2, numberOfIndexBits) + ".");
            }
            else
            {
                Demonstrations.Add("Number of sets in cache = Number of blocks/associativity type = (" + cacheSizeValue / blockSizeValue + ")/(" + SelectedAssociativity + ")= ");
                Demonstrations.Add(numberOfBlocksOrSets + ".");
            }
            #endregion
        }