Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <unistd.h>
- #include <getopt.h>
- //Systems Progamming lab 3
- //Cache Lab
- // /*
- // int main(int argc, char **argv){
- // int opt;
- // int x;
- // int y;
- // /* looping over arguments */
- // while(-1 != opt = getopt(argc, argv, "x:y"))){
- // /* determine which argument it's processing */
- // switch(opt) {
- // case 'x':
- // x = atoi(optarg);
- // break;
- // case 'y':
- // y = atoi(optarg);
- // break;
- // default:
- // printf("wrong argument \n");
- // break;
- // }
- // }
- // }
- // /*
- // Suppose the program executable was called “foo”.
- // Then we would call “./foo -x 1 –y 3“ to pass the value 1
- // to variable x and 3 to y.
- // */
- // */
- int main(int argc, char **argv) {
- /*
- FILE * pFile; //pointer to FILE object
- pFile = fopen ("tracefile.txt",“r"); //open file for reading
- char identifier;
- unsigned address;
- int size;
- // Reading lines like " M 20,1" or "L 19,3"
- while(fscanf(pFile,“ %c %x,%d”, &identifier, &address, &size)>0)
- {
- // Do stuff
- }
- fclose(pFile); //remember to close file when done
- */
- //reading the file
- // FILE *pFile;
- // pFile = fopen("address01.txt", "r");
- // unsigned cacheAddress;
- // while(fscanf(pFile, "%x", &cacheAddress)>0) {
- int opt;
- int m; //The size of address used in the cache (bit)
- int s; //The number of index bits (S = 2s is the number of sets)
- int e; //The number of line bits (E = 2e is the number of lines; associativity)
- int b; //The size of block bits (B = 2b is the block size)
- char i; //A set of addresses (file name)
- char r; //Page Replacement Algorithm – FIFO/Optimal/LRU
- while(-1 != (opt = getopt(argc, argv, "m:s:e:b:i:r"))) {
- switch(opt) {
- case 'm':
- m = atoi(optarg);
- break;
- case 's':
- s = atoi(optarg);
- break;
- case 'e':
- e = atoi(optarg);
- break;
- case 'b':
- b = atoi(optarg);
- break;
- default:
- printf("wrong argument \n")
- break;
- case 'i':
- i = (optarg);
- break;
- case 'r':
- r = (optarg);
- break;
- }
- }
- //reading the file
- FILE *pFile;
- pFile = fopen("address01.txt", "r");
- unsigned cacheAddress;
- unsigned long int set;
- unsigned long int tag;
- while(fscanf(pFile, "%x", &cacheAddress)>0) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement