Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DirectMappingCache {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter main memory size : ");
- int a = sc.nextInt();
- System.out.println("Enter size of Cache Memory : ");
- int b = sc.nextInt();
- System.out.println("Size of each block : ");
- int c = sc.nextInt();
- int tag = (int) (Math.log(a/b)/Math.log(2));
- int set = (int) (Math.log(b/c)/Math.log(2));
- int word = (int) (Math.log(c)/Math.log(2));
- for (int i = 0; i < 3; i++) {
- System.out.print(" _______");
- }
- System.out.println();
- for (int i = 0; i < 3; i++)
- System.out.print("| ");
- System.out.println("|");
- System.out.print("| " + tag + " ");
- System.out.print("| " + set + " ");
- System.out.print("| " + word + " ");
- System.out.println("|");
- for (int i = 0; i < 3; i++) {
- System.out.print("|_______");
- }
- System.out.println("|");
- System.out.print(" tag set word");
- }
- }
- /*
- Enter main memory size :
- 65536
- Enter size of Cache Memory :
- 4096
- Size of each block :
- 16
- _______ _______ _______
- | | | |
- | 4 | 8 | 4 |
- |_______|_______|_______|
- tag set word
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement