Advertisement
sandeshMC

Direct Mapping Cache

Apr 12th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DirectMappingCache {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner sc = new Scanner(System.in);
  8.         System.out.println("Enter main memory size : ");
  9.         int a = sc.nextInt();
  10.         System.out.println("Enter size of Cache Memory : ");
  11.         int b = sc.nextInt();
  12.         System.out.println("Size of each block : ");
  13.         int c = sc.nextInt();
  14.         int tag = (int) (Math.log(a/b)/Math.log(2));
  15.         int set = (int) (Math.log(b/c)/Math.log(2));
  16.         int word = (int) (Math.log(c)/Math.log(2));
  17.         for (int i = 0; i < 3; i++) {
  18.             System.out.print(" _______");
  19.         }
  20.         System.out.println();
  21.         for (int i = 0; i < 3; i++)
  22.             System.out.print("|       ");
  23.         System.out.println("|");
  24.         System.out.print("|   " + tag + "   ");
  25.         System.out.print("|   " + set + "   ");
  26.         System.out.print("|   " + word + "   ");
  27.         System.out.println("|");
  28.  
  29.         for (int i = 0; i < 3; i++) {
  30.             System.out.print("|_______");
  31.         }
  32.         System.out.println("|");
  33.         System.out.print("   tag     set     word");
  34.  
  35.     }
  36.  
  37. }
  38.  
  39. /*         
  40. Enter main memory size :
  41. 65536
  42. Enter size of Cache Memory :
  43. 4096
  44. Size of each block :
  45. 16
  46.  _______ _______ _______
  47. |       |       |       |
  48. |   4   |   8   |   4   |
  49. |_______|_______|_______|
  50.    tag     set     word
  51.    */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement