3.8 MIC-1 Linker

In C, write a linker for MIC-1 assembly. In MIC-1 assembly, redo MIC-1 Calculator using separate functions (discussed below) and use your linker to link them into a single object.

The masm program normally produces consolidated object files that are pure binary strings of MIC-1 assembly instructions. In these consolidated files, the presence of symbolic labels is gone and their use is replaced with actual memory locations.

However, when masm receives the -o argument, it produces unresolved object files where symbolic labels have not been rewritten. The format of these files is as follows:

 

unresolved file

 ::= 

body separator symbol table

 

body

 ::= 

instruction*

 

instruction

 ::= 

unresolved instruction

 

  |  

resolved instruction

 

unresolved instruction

 ::= 

memory location U binary string symbol \n

 

resolved instruction

 ::= 

memory location binary string \n

 

separator

 ::= 

4096 x \n

 

symbol table

 ::= 

symbol table entry*

 

symbol table entry

 ::= 

symbol memory location \n

 

memory location

 ::= 

Number between 0 and 4095.

 

binary string

 ::= 

Sixteen (16) binary characters, either 0 or 1.

 

symbol

 ::= 

String matching [A-Za-z][0-9A-Za-z]*.

A linker receives some number of unresolved object files and combines them together into a single consolidated object file. This process works by combining all of the bodys and symbol tables, adjusting their starting locations, then rewriting each unresolved instruction such that the final twelve (12) bits of the binary string are replaced with the memory location the symbol refers to in the combined, adjusted symbol table. This process is undefined if the symbol table contains duplicate entries.

Your linker should accept unresolved object files by name on the command-line and output the consolidated object file on standard output.

Your new version of MIC-1 Calculator must provide the following functions:
  • void main() - the main routine for the program.

  • int readint() - this routine must read a positive-only integer from the keyboard, and return it.

  • void writeint(int binary_int) - this routine must take a single, positive-only binary integer as an argument, and write the integer to the output display.

  • void writestr(widechar *strptr) - this routine must take a single argument in the form of a memory location and print the entire string starting at that location to the output display.

  • int addints(int x, int y) - this function must take two arguments, each a positive-only integer, and compute the sum of the two integers and return the sum or a return a twos-complement value of -1 if the addition would overflow.

  • void rbsywt() - when this function returns, it is safe to load an ASCII character from the receiver buffer (location 4092).

  • void xbsywt() - when this function returns, it is safe to store an ASCII character into the transmitter buffer (location 4094).

In all other ways, the MIC-1 program should be identical to what is described in MIC-1 Calculator.

You must turn in
  • A README file that contains a short write-up of your project. It should discuss the approach you took to solving the problem, it should discuss any problems or issues that still remain, it should discuss any interesting things that you learned in the course of the project. Finally, it should provide the grade you believe the project deserves with a detailed explanation of why. This explanation should almost certainly focus on why you believe the program is correct.

    This file must be in plain-text. If you need formatting, use Markdown. It must be limited to 80 characters wide, unless you are quoting program output.

  • Your C linker source, named linker.c.

  • Your assembly program source, named main.asm, readint.asm, writeint.asm, writestr.asm, addints.asm, xbsywt.asm, and rbsywt.asm.

  • Your unresolved object files, produced with masm -o, named main.o, readint.o, writeint.o, writestr.o, addints.o, xbsywt.o, and rbsywt.o.

  • Your consolidated object file, produced with linker, named calc.o.

  • A test input file, named test.in. See MIC-1 Calculator for details.

  • A test output file, named test.out, that contains the expected output for the test input file.

  • A Makefile that builds your linker, compiles the unresolved objects, links them together, then runs the program and then tests it by running it with test.in as the input and compares the actual output to test.out. You may assume that the masm binary from MIC-1 Microcode Extension is in the PATH. You may also assume that the mic1 binary is in the PATH and that rmd.prom is a compiled, correct microcode interpreter from MIC-1 Microcode Extension.

This assignment will be graded based on its correctness and your ability to articulate why it is correct.