import java.io.*; import java.util.StringTokenizer; class lab5 { public static String padStr( Object inObj, int strLen ) { return padStr( inObj, strLen, ' ' ); } public static String padStr( Object inObj, int strLen, char padChar ) { String inStr = inObj.toString(); String toReturn = new String(); for( int i=0 ; i" ); System.exit( 0 ); } try { br = new BufferedReader( new FileReader( argv[0] ) ); long type, addr, inst, mask; // read first 100 lines of trace file; // address holds virtual address in unsigned int format; // N.B. - your program must read all 1,000,000 lines but // you might want to test it on the first 100 lines // or so before running it on the entire trace file! for( int i=0 ; i<100 ; i++ ) { StringTokenizer st = new StringTokenizer( br.readLine() ); try { type = Long.parseLong( st.nextToken(),16 ); addr = Long.parseLong( st.nextToken(),16 ); inst = Long.parseLong( st.nextToken(),16 ); // 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 mask = ( addr&0x000000f0L ) >> 4; System.out.println( padStr( Long.toString( addr,16 ),8 )+" "+padStr( mask+"",2 ) ); } catch( NumberFormatException nfe ) { System.out.println( "Not a Hex number: "+nfe ); } } } catch( FileNotFoundException fnfe ) //from FileReader { System.out.println( "File not found: "+fnfe ); System.exit( 0 ); } catch( EOFException eof ) //from BufferedReader { System.out.println( "End of file." ); System.exit( 0 ); } catch( Exception e ) { System.out.println( "Error: "+e ); System.exit( 0 ); } } }