CS520
Fall 2017
Program 3
Due Wednesday October 11


Write a disassembler for the RISC-V machine language.

Your disassembler only needs to handle the RISC-V RV-32I base instruction set.

The RISC-V machine code will be in a 64-bit, little-endian ELF file.

Your program should take a single command-line argument, the name of the ELF file to be disassembled. It should write its output to stdout.

Each instruction should be displayed on its own line, with no leading spaces. Each instruction should be displayed using the exact format used on the one-page RISC-V RV-32I document linked above, with one exception: print the opcode in lowercase. (The format to be followed is listed on the far right-hand side of the one-page document.) Note that there is a single space separating the opcode from the operands, and there are no spaces following the commas separating the operands. Also, please do not print any blank lines, any header lines, or anything else. We plan to use automated output file checking (the diff or cmp commands), so be sure to follow this specification exactly. And please raise questions if you do not think these directions are specific enough.

The immediate constant values should be displayed in decimal, and the value displayed should be the value intended, not the value of the bits in the immediate constant field. For example, the immediate constant value in the SB instructions is shifted left 1 position (multiplied by 2) to get its intended value. Immediate constants are signed values.

Register numbers should be displayed in decimal with a lowercase "x" prepended.

The shamt (shift amount) field should be displayed in decimal and is unsigned.

If your program encounters an instruction it cannot handle then it should print "unknown" on its output line and go on to the next instruction. You should make your program robust so that it can handle errors such as:

You do not need to error check the "pred" or "succ" fields of the FENCE instruction.

Put your source code in a single file called "disRISCV.c".

In the ~cs520/public/prog3 directory there are ELF files containing RISC-V machine code. This directory also contains some "dump" files that contain the expected output for the corresponding ELF files, as well as the assembly language files used to create the ELF files. (Note that the disassembler will not re-create the assembly language exactly.)

The RISC-V assembler is available on agate as ~cs520/bin/asRISCV. Run it with the "--help" flag to learn more about using it. Basically you need to give it a file to be assembled, which should use the ".s" extension, and you should use the "-o" flag to set the output file name.

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

Leave the Lab 5 and Lab 6 output to stderr on for your Program 3 submission. But be sure that this output goes to stderr and that the disassembled instruction output goes to stdout.

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. I also want to see that you applied the principles of problem decomposition, incremental development and incremental testing. Leave your debugging output in your code, but disabled, when you do your final assignment submission.

Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment. Your programs will be compiled using these gcc flags: -g -Wall -std=c99.

Your programs should be submitted for grading from agate.cs.unh.edu. To turn in this assignment, type:
~cs520/bin/submit prog3 disRISCV.c

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

This assignment is due Wednesday October 11. The standard late policy concerning late submissions will be in effect. See the course overview webpage.

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!


Last modified on September 13, 2017.

Comments and questions should be directed to pjh@cs.unh.edu