fork download
  1.  
  2.  
  3.  
  4. class Instruction
  5. {
  6. String inst;
  7. int history;
  8. Instruction()
  9. {
  10. history=0; // Assume Strongly Taken
  11. }
  12. }
  13.  
  14.  
  15.  
  16. class BranchPredictionLogic
  17. {
  18. public static void main(String args[]) throws Exception
  19. {
  20. int d,ch;
  21. String his="Strongly Taken";
  22. Instruction i1;
  23. String HistoryArray[]={"Strongly Taken","Weakly Taken","Weakly Not Taken","Strongly Not Taken"};
  24. System.out.println("Active Prefetch Queue A");
  25.  
  26. i1=new Instruction();
  27. System.out.println("Enter instructions:");
  28. while(true)
  29. {
  30. i1.inst=br.readLine();
  31. if(isBranchInst(i1.inst)==true)
  32. break;
  33. }
  34.  
  35. System.out.println(i1.inst+" is a Branch Instruction");
  36.  
  37. System.out.println("\n\n***DECODE1 STAGE***");
  38. System.out.println("*****Branch Target Buffer*****");
  39.  
  40. System.out.println("Source:----\nTarget:-----\nHistory: Strongly Taken");
  41. do{
  42. System.out.println("\n\n\n*****EXECUTE STAGE*****");
  43. System.out.println("Does branch take place?? Enter 1 or 0 : ");
  44. d=Integer.parseInt(br.readLine());
  45.  
  46. updateLogic(i1,d);
  47.  
  48. System.out.println("***New Branch Target Buffer***");
  49. his=HistoryArray[i1.history];
  50. System.out.println("Source:----\nTarget:----\nHistory: "+his);
  51.  
  52. System.out.println("Do you want to continue:(1/0): ");
  53. ch=Integer.parseInt(br.readLine());
  54.  
  55. }while(ch!=0);
  56.  
  57. }
  58.  
  59. public static boolean isBranchInst(String x)
  60. {
  61. String jumpInstructions[]={"JC","JMP"};
  62.  
  63. for(int i=0;i<jumpInstructions.length;i++)
  64. if(x.equals(jumpInstructions[i])==true)
  65. return true;
  66.  
  67. return false;
  68. }
  69.  
  70. public static void updateLogic(Instruction i,int n)
  71. {
  72. int history[]={0,1,2,3};
  73. int historyAfterTaken[]={0,0,1,2};
  74. int historyNotTaken[]={1,2,3,3};
  75.  
  76. if(n==1)
  77. {
  78. System.out.println("\nContents of B queue are valid!!!!!");
  79. i.history=historyAfterTaken[i.history];
  80. }
  81. else if(n==0)
  82. {
  83. System.out.println("Contents of B queue not valid\nActive PrefetchQueue is A");
  84. i.history=historyNotTaken[i.history];
  85. }
  86. }
  87. }
  88.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:24: error: cannot find symbol
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  ^
  symbol:   class BufferedReader
  location: class BranchPredictionLogic
Main.java:24: error: cannot find symbol
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        ^
  symbol:   class BufferedReader
  location: class BranchPredictionLogic
Main.java:24: error: cannot find symbol
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                                           ^
  symbol:   class InputStreamReader
  location: class BranchPredictionLogic
3 errors
stdout
Standard output is empty