CS520
Spring 2014
Laboratory 5
Monday February 24
The lab must be submitted prior to 8am on Tuesday February 25.


Write a program to decode a vm520 object file. The file to be decoded will be provided as the single command-line argument.

The structure of a vm520 object file is described in the second half of this document.

Your program should do the following steps:

  1. Open the file. If the open fails, print an error message to stderr and terminate the program.

  2. Read the three header words containing the lengths of the insymbol, outsymbol and object-code sections. Display to stdout the lengths in decimal in the following way:
    Insymbol Length 100
    OutSymbol Length 100
    Object-Code Length 100
    

  3. Skip over the insymbol and outsymbol section by reading from the file until you reach the beginning of the object-code section.

  4. Read each word in the object-code section and interpret it as an instruction. Display to stdout the opcode for the word in both hex and in text. For example,
    18 push
    
    The words should be displayed one per line. If the word does not contain a valid opcode, print "unknown" on the line.

If the file structure is corrupt (the sum of the header words is not the actual length of the file), then print an error message to stderr and terminate the program.

There are some sample object files available on agate in ~cs520/public/lab5. Remember that your program is intended to process object files, and not the assembly language source files.

You can also create your own tests using the vm520 assembler, called as520. And you can look inside an object file using the vm520 disassembler, called dis520. Both of these tools are installed on agate in ~cs520/bin.

Points will be awarded for the lab in the following way:

To turn in this laboratory, type:
~cs520/bin/submit lab5 lab5.c

Submissions can be checked by typing:
~cs520/bin/scheck lab5


Last modified on February 20, 2014.

Comments and questions should be directed to hatcher@unh.edu