COSC 065 Hardware Systems

Fall 2008

Homework Assignment #4

Due: Wednesday, October 8th, 2:00pm CDT (start of class)
Submit: Turn in your "HexDump.java" using the turnin command on Morbius.
Work may be completed in teams of two. The names of both partners must appear in a comment block at the top of your file for credit to be given.

This UNIX tutorial may be of some assistance.

Hex Dump

You are to write a Java program that takes a single file name as a command-line argument, and prints out the contents of that file as specified below.

The output format looks like this:

00000000   69 6D 70 6F 72 74 20 6A   61 76 61 2E 69 6F 2E 46   |import java.io.F|
00000010   69 6C 65 49 6E 70 75 74   53 74 72 65 61 6D 3B 0A   |ileInputStream;.|
00000020   69 6D 70 6F 72 74 20 6A   61 76 61 2E 69 6F 2E 46   |import java.io.F|
00000030   69 6C 65 4E 6F 74 46 6F   75 6E 64 45 78 63 65 70   |ileNotFoundExcep|
00000040   74 69 6F 6E 3B 0A 69 6D   70 6F 72 74 20 6A 61 76   |tion;.import jav|
00000050   61 2E 69 6F 2E 49 4F 45   78 63 65 70 74 69 6F 6E   |a.io.IOException|
00000060   3B 0A 0A 70 75 62 6C 69   63 20 63 6C 61 73 73 20   |;..public class |
00000070   48 65 78 44 75 6D 70 0A   7B 0A 20 20 20 20 70 75   |HexDump.{.    pu|
00000080   62 6C 69 63 20 73 74 61   74 69 63 20 53 74 72 69   |blic static Stri|
00000090   6E 67 20 74 6F 48 65 78   28 69 6E 74 20 63 6F 6E   |ng toHex(int con|
...

The first column is the "address", a zero-based integer count of the bytes seen in the input file. It should be expressed as a 32-bit hexadecimal quantity.

The next 16 small columns contain 8-bit hexadecimal representations of the bytes in the file, in order, left to right.

The final large column contains an ASCII interpretation of the file's contents.

Reference Implementation

The professor has provided an example program for your reference, runnable on Systems Lab machines as ~brylow/cosc065/bin/HexDump.

Pay close attention to the finer details of the output! Try to match the reference implementation as closely as you can:

  • What happens to bytes that have no printable ASCII value?
  • What happens at the end of the file?
  • Proper formatting of the columns makes the difference between a usable tool and a bunch of gobbledygook.
  • Note that your professor hates lowercase hexadecimal numbers.

    Analysis

  • Run your HexDump program on your Java source file. What do you see?
  • Run your HexDump program on your Java .class file. What do you see? Try several other .class files. What do they have in common? (Hint: Piping your output into Unix commands like more and head can help you examine the beginning the output at a more measured pace.)
  • Use gcj to generate an executable file, rather than a platform-independent .class file. How does the HexDump of the contents of the executable file compare with the .class file?
  • Use your HexDump tool to examine the beginnings of several other programs on the workstations. What do these have in common?
  • What to turn in:

  • Submit your HexDump.java file using the turnin command, as shown in lab. Submit only one copy per team. You may turnin as many times as you like -- only the last submission is kept. The turnin system automatically disengages at the deadline.
  • Submit a hardcopy of your team's answers to the analysis questions at the beginning of class on the due date.

  • Back
    [Revised 2008 Oct 08 13:12 DWB]