CS611
Fall 2003
Programming Assignment 2
Due Sunday September 28


Write a disassembler for vm611 object files.

The encoding of vm611 instructions and the structure of an vm611 object file is defined in this description of vm611.

Your program should read an object file from stdin and dump its contents to stdout.

The first line in the output should contain only the length of the instruction section in units of 4-bit nibbles. The length should be printed in decimal.

The instructions in the instruction section should then be dumped in order, one instruction per line. Each line should begin with the address of the instruction, displayed in hexadecimal, with exactly three hex digits, using leading 0's if necessary. Following the address should be a single space and then the instruction.

The single-nibble instructions ("add", "sub", etc.) should be displayed by printing only the opcode mnemonic.

The "branch" and "call" instructions should be displayed by printing the opcode mnemonic, a space, and the address in hexadecimal. The address contained in the instruction should then be printed with exactly three hex digits, using leading 0's if necessary.

The "push" and "pop" instructions should be displayed by printing either the opcode ("push" or "pop") or virtual opcode ("pushind", "pushloc", "popind", or "poploc") mnemonic, a space, and then either an address in hexadecimal, a constant in decimal, or nothing (for "pop" with immediate operand type). When printing an address, print exactly three hex digits, using leading 0's if necessary. See the description of the vm611 assembler, as611, for more information about virtual opcodes for the "pop" and "push" instructions.

After printing all instructions, then print the contents of the data section one 32-bit word per line. Each line should begin with the address of the line's word, printing in hexadecimal using exactly three hex digits, using leading 0's if necessary.

Each word should be displayed twice: once in hexadecimal and once in decimal. The hexadecimal should appear first on the line. The decimal should follow, separated by a single space. When printing the hexadecimal, print exactly eight digits, using leading 0's if necessary.

If there is no data section, then no lines should be printed after the instructions are dumped.

Remember that the input file is not human-readable. You can examine input files using the od (octal dump) tool. For example, the following will display the file one byte at a time using hexadecimal:
od -tx1 file.obj

Be aware, however, that the first thing that od displays on a line is the octal offset of the first byte on the line. For more information, see
man od

Look in ~cs611/public/prog2 for some test files. You may need to create other test files as well. Tests can be created by writing assembly language programs and translating them to object files by using the vm611 assembler.

Grading will be based upon completed, correct functionality:

Your program will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented. See the mandatory guidelines given in the course overview webpage.

You must write your program in C.

Put all your code in a file called dis.c.

Your assignment should be submitted for grading from a CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs611/bin/submit prog2 dis.c

Do not turn in any other files!

Submissions can be checked from a CIS Linux machine by typing:
~cs611/bin/scheck prog2

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday September 29. Late submissions will be accepted at the penalty of 5 points per day up to one week late.

Your programs will be graded using a CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment.

Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!

If you developed your code on a DOS/Windows system, be sure to appropriately transfer your files to a CIS Linux system before submitting them. You need to convert the DOS ASCII file format to UNIX format. If you need help with this, please see me.


Last modified on September 16, 2003.

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