CS520
Fall 2013
Lab 4
Due Wednesday, September 25


Printing the raw opcodes and operands

Begin this lab by downloading the files for program 3. You will need to modify the disassemble.c file. For this lab, you are to only modify that file, and are not to add any other files or change the makefile. For the overall program, this restriction is lifted.

Output

Your program should function as follows:
./dis_class ../classfile/tests/Pathetic.class 
Method Name: 
2a b7 00 01 b1 
Method Name: main
b1 
./dis_class ../classfile/tests/Multinewarray.class 
Method Name: 
2a b7 00 01 b1 
Method Name: main
05 08 c5 00 02 02 4c b1 
There is to be 1 command line argument, which should be a java class file. You may assume the input argument, if present, is a valid java class file. The starter code is currently about to read in the entire class file, and print out information found in the class file in human readable form, but it currently uses the default printing function, which you don't want to be using, because it prints way too much stuff out; you only want information about one method.

The format is as follows: Each method should be printed on two lines. The first line should contain the words, "Method Name:" followed by a space, followed by the method's name as looked up in the constant table. On the next line the entire contents of the method character string should be printed out, one at a time. The characters should be printed in hex, always printing 2 characters, followed by a space after each character, including the last character. Note that we want only the code, not the entire contents of the attribute_info field.

Reference Solution

Once again, I am providing a sample binary for you to compare against. I expect your program and this binary to produce identical outputs. It can be copied from ~cs520/lab5_ref which is world readable.

Testing

In order to do testing, you will need to create some java class files. I assume everyone in this class is familiar enough with java to be able to compile and build java programs. For example, here is a simple test.
-bash-4.2$ ./dis_class ../classfile/tests/Pathetic.class > Pathetic.mine
-bash-4.2$ ~cs520/lab5_ref ../classfile/tests/Pathetic.class > Pathetic.ref
-bash-4.2$ diff Pathetic.mine Pathetic.ref 
-bash-4.2$ cat Pathetic.mine
Method Name: 
2a b7 00 01 b1 
Method Name: main
b1 
-bash-4.2$ 
The > redirects the standard out stream from the program to a file, in the first case the file is named Pathetic.mine and the second is called Pathetic.ref. Next, the diff program compares the two outputs and notes what the differences, if any, are. Testing files like that one at a time is labor intensive and annoying if there are a lot of files you want to test. It may be worth investing in learning how to make bash scripts (if you're old school) or python scripts (if you're new school) to automate this testing. For example, the grading scripts are all python scripts that automatically run the programs and look at the outputs, which is very effective for identifying stuff that passes perfectly.

Detailed instructions

  1. Log on to one of the computers in the lab.
  2. Open up a terminal
  3. Go to the directory where you started your program 3, with all of the starter code.
  4. To compile this program type:
    make
    and the make tool will construct your program.
  5. Write the necessary code in the disassemble.c file.
  6. When you are done, submit your source file. In order to submit your file, you will need to be SSH'd in to agate.
    ~cs520/bin/DoSubmission.py lab5 disassemble.c
    I will use my own copy of the makefile and other components. The only difference is I will call disassemble(cf) instead of print_classfile(cf, stdout) and I will have disasemble.h not commented out.

Submitting

Please submit whatever you have at the end of lab, even if it is incomplete. You have the rest of today to finish this assignment.

Grading

Your program will be graded primarily by testing it for correct functionality.

In addition, remember, you may lose points if your program is not properly structured or adequately documented. Coding guidelines are given on the course overview webpage.

Next Steps

The major difficulty in this lab is getting to know the starter code. For example, I was able to do this lab in approximately 5-10 minutes, because I am very familiar with the starter code. The next step is identifying the opcodes and starting to find what name each opcode has. The wikipedia article has the opcodes listed by name, argument count, and function. You will need to figure out a good way to map opcodes to names. The primary difficulty here is getting all of the opcodes and their names into your program.