CS520
Spring 2014
Programming Assignment 3
Due Thursday March 6 (extension granted to Saturday March 8)


Write a C function, translateBinary, to translate vm520 instructions to Intel 64 instructions.

The function should take three arguments:

  1. The name of the vm520 object file to be translated.

  2. A buffer into which the Intel 64 instructions should be written.

  3. The length of the buffer in units of bytes.

You may make a number of simplifying assumptions about the vm520 object file being translated: Your translation should follow these strategies: During translation you may print an appropriate error message to stderr and halt the program if any of these things happen: The directory ~cs520/public/prog3 contains sample code for this assignment:
  1. allocateInstructionBuffer.c: contains code for allocating a buffer where Intel 64 instructions can be written and then executed. You should not change this code. And please note that this code cannot be compiled with the -std=c99 flag.

  2. translateSumVector.c: contains an implementation of translateBinary that does not read a vm520 object file, but rather just hardcodes Intel 64 instructions to implement the sumVector.obj example that is available on agate in ~cs520/public/vm520-examples. This file contains a lot of examples of how to translate vm520 instructions to Intel 64 instructions.

  3. mainSumVector.c: a main program that utilizes the other two files. Especially note how the translated code is executed. Also note how the main program can reach into the translated code to retrieve the result of the computation, but must remember that vm520 words are implemented with Intel quadwords.

  4. This code can be compiled and executed in the following way:
    gcc -c -Wall allocateInstructionBuffer.c
    gcc -Wall -std=c99 translateSumVector.c mainSumVector.c allocateInstructionBuffer.o
    a.out
    

Your program will be graded primarily by testing it for correct functionality:
  1. 60 points - handle vm520 programs that contain HALT, LOAD, STORE and LDIMM instructions (as well as the initial JMP instruction and a data section).

  2. 20 points - also handle ADDI, SUBI, DIVI and MULI instructions.

  3. 10 points - also handle BLT, BGT and BEQ instructions, as well as the general use of the JMP instruction.

  4. 10 points - also handle LDADDR, LDIND and STDIND instructions.

These items are listed in the order that you should tackle them. For example, the testing of the branch/jump instructions will assume that you have HALT, LOAD, STORE, LDIMM, ADDI, SUBI, DIVI and MULI working.

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

Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment.

You should submit all the source code for your implementation of the translateBinary routine in a single file called translateBinary.c.

You must turn-off any debugging code before you submit your program.

Your submitted file will be compiled using the following:
gcc -c -g -Wall -std=c99 translateBinary.c

Note: you are only submitting the one file, translateBinary.c, so do not put any of your code in any other file. In particular, translateBinary.c should not include any files that you created. It should only include standard system header files. In addition, it should not contain a main function, nor should it contain the allocateInstructionBuffer function.

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

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

This assignment is due Thursday March 6 (extension granted to Saturday March 8). 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.


Last modified on March 3, 2014.

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