/* ECE 3055 Computer Architecture and Operating Systems read_trace.c School of Electrical and Computer Engineering Georgia Institute of Technology Atlanta, GA 30332 */ #include void main(int argc, char *argv[]) { FILE *fp; int i, type; long long unsigned address; unsigned int instr; unsigned int masked_addr; if (argc==1) { fprintf(stderr, "Usage: \n"); exit(-1); } // open trace file for reading fp = fopen(argv[1], "r"); // read first 100 lines of trace file for testing; // address holds virtual address in unsigned int format; // // Your final program must read through the end of each trace // but you might want to test it on the first 100 lines // or so before running it on the entire trace file! i = 0; while ( (fscanf(fp, "%d %llx %x", &type, &address, &instr))!=EOF && i<100) { // read 1 line of trace file at a time // example of bit-wise operation in C; // mask off all but the 2nd least significant hex digit, // shift right by 4 bits, and print address in hex and // masked shifted address in decimal masked_addr = (address & 0x000000f0) >> 4; printf("%12llx %2d\n", address, masked_addr); i++; } }