Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include <unistd.h>
  14. #include <getopt.h>
  15.  
  16. //Systems Progamming lab 3
  17. //Cache Lab
  18.  
  19. // /*
  20. // int main(int argc, char **argv){
  21. // int opt;
  22. // int x;
  23. // int y;
  24. // /* looping over arguments */
  25. // while(-1 != opt = getopt(argc, argv, "x:y"))){
  26. // /* determine which argument it's processing */
  27. // switch(opt) {
  28. // case 'x':
  29. // x = atoi(optarg);
  30. // break;
  31. // case 'y':
  32. // y = atoi(optarg);
  33. // break;
  34. // default:
  35. // printf("wrong argument \n");
  36. // break;
  37. // }
  38. // }
  39. // }
  40. // /*
  41. // Suppose the program executable was called “foo”.
  42. // Then we would call “./foo -x 1 –y 3“ to pass the value 1
  43. // to variable x and 3 to y.
  44. // */
  45. // */
  46.  
  47. int main(int argc, char **argv) {
  48. /*
  49. FILE * pFile; //pointer to FILE object
  50. pFile = fopen ("tracefile.txt",“r"); //open file for reading
  51. char identifier;
  52. unsigned address;
  53. int size;
  54. // Reading lines like " M 20,1" or "L 19,3"
  55. while(fscanf(pFile,“ %c %x,%d”, &identifier, &address, &size)>0)
  56. {
  57. // Do stuff
  58. }
  59. fclose(pFile); //remember to close file when done
  60.  
  61. */
  62.  
  63. //reading the file
  64.  
  65. // FILE *pFile;
  66. // pFile = fopen("address01.txt", "r");
  67. // unsigned cacheAddress;
  68.  
  69. // while(fscanf(pFile, "%x", &cacheAddress)>0) {
  70.  
  71. int opt;
  72. int m; //The size of address used in the cache (bit)
  73. int s; //The number of index bits (S = 2s is the number of sets)
  74. int e; //The number of line bits (E = 2e is the number of lines; associativity)
  75. int b; //The size of block bits (B = 2b is the block size)
  76. char i; //A set of addresses (file name)
  77. char r; //Page Replacement Algorithm – FIFO/Optimal/LRU
  78.  
  79. while(-1 != (opt = getopt(argc, argv, "m:s:e:b:i:r"))) {
  80.  
  81. switch(opt) {
  82.  
  83. case 'm':
  84. m = atoi(optarg);
  85. break;
  86.  
  87. case 's':
  88. s = atoi(optarg);
  89. break;
  90.  
  91. case 'e':
  92. e = atoi(optarg);
  93. break;
  94.  
  95. case 'b':
  96. b = atoi(optarg);
  97. break;
  98.  
  99. default:
  100. printf("wrong argument \n")
  101. break;
  102.  
  103. case 'i':
  104. i = (optarg);
  105. break;
  106.  
  107. case 'r':
  108. r = (optarg);
  109. break;
  110. }
  111. }
  112.  
  113. //reading the file
  114.  
  115. FILE *pFile;
  116. pFile = fopen("address01.txt", "r");
  117. unsigned cacheAddress;
  118.  
  119. unsigned long int set;
  120. unsigned long int tag;
  121.  
  122. while(fscanf(pFile, "%x", &cacheAddress)>0) {
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement