Exemple #1
0
        /// <summary>
        /// convert the binary value of the address to equivalent hexadecimal value
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        private string BinaryToHexadecimal(string address)
        {
            string tempAddress = "";

            if (!string.IsNullOrEmpty(address))
            {
                if (address.Length % 4 != 0)
                {
                    int closestFourMultiple = 4 * (address.Length / 4 + 1);
                    address = address.PadLeft(closestFourMultiple, '0');
                }
                int    subStringBegining = 0;
                string subStringHolder;
                while (subStringBegining < address.Length)
                {    //change each four characters -represinting binary values- to their hexadecimal equvlant
                    subStringHolder    = address.Substring(subStringBegining, 4);
                    tempAddress       += ValueConverterModel.GetHexadecimalValue(subStringHolder);
                    subStringBegining += 4;
                }
                return(tempAddress);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// convert the hexadecimal value of the address to equivalent binary value
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        private string HexadecimalToBinary(string address)
        {
            string tempAddress = "";

            if (!string.IsNullOrEmpty(address))
            {
                address = address.ToLower();
                for (int i = address.Length - 1; i >= 0; i--)
                {
                    tempAddress += ValueConverterModel.GetHexadecimalValue(address[i].ToString());
                }
                address = "";
                int subStringEnding = tempAddress.Length;
                while (subStringEnding >= 4)
                {
                    address         += tempAddress.Substring(subStringEnding - 4, 4);
                    subStringEnding -= 4;
                }


                return(address);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
 /// <summary>
 /// a function to fill all the values of the ram sizes that will be demonstraited so the user can choose one value
 /// </summary>
 private void FillRamSize()
 {
     RamSizes = new List <string>();
     foreach (var item in CacheModel.RamSizes)
     {
         RamSizes.Add(ValueConverterModel.ConvertToString(item));
     }
 }
Exemple #4
0
 /// <summary>
 /// a function to fill all the values of the associativity type that will be demonstraited so the user can choose an associativity type
 /// </summary>
 private void FillAssociativityType()
 {
     Associativities = new List <string>();
     foreach (var item in CacheModel.Associativities)
     {
         Associativities.Add(ValueConverterModel.ConvertToWays(item));
     }
 }
Exemple #5
0
 public void InitiliazeData()
 {
     CacheModel              = new CacheModel();
     ValueConverterModel     = new ValueConverterModel();
     IndexTagOffsetContainer = new Dictionary <string, HashSet <string> >();
     CacheBlocksPresented    = new ObservableCollection <PresentationModel>();
     Demonstrations          = new ObservableCollection <string>();
     FillCacheSize();
     FillAssociativityType();
     FillRamSize();
 }
Exemple #6
0
        /// <summary>
        /// The function that will be called once the <see cref="AddressCalculatingCommand"/> is invoked
        /// calculates the tag,index/set,offset bits from the requested address
        /// </summary>
        public void AddressCalculatingCommandExecute()
        {
            BoolHitOrMiss = false;
            string tempAddress = RequestAddress;

            OnCacheAlgorithimStart();
            if (tempAddress.Length < TotalNumberOfBits)
            {
                tempAddress = tempAddress.PadLeft(TotalNumberOfBits, '0');
            }
            if (!IsBinary)
            {
                tempAddress = HexadecimalToBinary(tempAddress);
            }
            // holds the integer value representing the size of the cache
            int cacheSizeValue = int.Parse(RegexFunction(SelectedCacheSize, true)) * ValueConverterModel.ConvertMemorySizeTypeToByte(RegexFunction(SelectedCacheSize, false));
            //holds the integer value representing the size of the blocks
            int blockSizeValue = int.Parse(RegexFunction(SelectedBlockSize, true));
            //the number of blocks in the cache
            int numberOfBlocks = cacheSizeValue / blockSizeValue;
            // the number of bits int the index part of the requested address
            int numberOfIndexBits = 0;
            //the number of bits the tag part of the requested address
            int numberOfTagBits = 0;
            // the number of bits int he index part of the requested address in the set associativity algorithm type
            int numberOfIndexBitsSetAssociativity = 0;
            //the number of bits the tag part of the requested address  in the set associativity algorithm type
            int numberOfTagBitsSetAssociativity = 0;
            //holds the integer value representing the type of associativity
            int associativityTypeValue = 0;
            int numberOfSets           = 0;

            if (IsDirectMapping)
            {
                FirstColumnName   = "Block Number";
                numberOfIndexBits = GetLogValue(numberOfBlocks);
                numberOfTagBits   = GetLogValue(RamSizeToInt) - GetLogValue(blockSizeValue) - numberOfIndexBits;
                BinaryToDecimal_TagIndexOffsetAssignmentnFunction(tempAddress, numberOfBlocks, blockSizeValue, numberOfIndexBits, numberOfTagBits, cacheSizeValue);
            }
            else
            {
                FirstColumnName                   = "Set Number";
                associativityTypeValue            = int.Parse(RegexFunction(SelectedAssociativity, true));
                numberOfSets                      = numberOfBlocks / associativityTypeValue;
                numberOfIndexBitsSetAssociativity = GetLogValue(numberOfSets);
                numberOfTagBitsSetAssociativity   = GetLogValue(RamSizeToInt) - GetLogValue(blockSizeValue) - numberOfIndexBitsSetAssociativity;
                BinaryToDecimal_TagIndexOffsetAssignmentnFunction(tempAddress, numberOfSets, blockSizeValue, numberOfIndexBitsSetAssociativity, numberOfTagBitsSetAssociativity, cacheSizeValue);
            }
            HitOrMissFunction();
            CanWrite = true;
        }
Exemple #7
0
        /// <summary>
        /// a function to fill all the values of the block sizes that will be demonstraited so the user can choose one value
        /// </summary>
        private void FillBlockSize()
        {
            BlockSizes = new ObservableCollection <string>();
            int halfOfCacheSize = (int.Parse(RegexFunction(SelectedCacheSize, true)) * ValueConverterModel.ConvertMemorySizeTypeToByte(RegexFunction(SelectedCacheSize, false))) / 2;

            foreach (var item in CacheModel.BlockSizes)
            {
                if (item <= halfOfCacheSize)
                {
                    BlockSizes.Add(ValueConverterModel.ConvertToString(item));
                }
                else
                {
                    break;
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// when ram size been selected the user can enter the address
 /// </summary>
 private void IsRamSizeSelected()
 {
     CanWrite          = true;
     RamSizeToInt      = int.Parse(RegexFunction(SelectedRamSize, true)) * ValueConverterModel.ConvertMemorySizeTypeToByte(RegexFunction(SelectedRamSize, false));
     TotalNumberOfBits = GetLogValue(RamSizeToInt);
 }