Problems Encountered

We didn't face any serious problems in the required sections of the lab. We had some diffictulty figuring out how to use the Flags register as both an input and an output, but that problem was solved by defining the register to be of type Inout. When we first implemented our division algorithm, we intended to implement the two's complement algorithm but instead implemented the unsigned division algorithm. Our first division algorithm, therefore, only worked if the divisor and the dividend were both positive. We were trying to find the average of positive and negative numbers. Since the sum of the numbers was positive (and, consequently both numbers used in the division were positive), the algorithm "worked" even though it was not implemented correctly.

To make our division algorithm more robust, we decided to implement the two's complement division algorithm. In that algorithm, there are three different points at which the signs of two numbers must be compared. To do this without overwriting one of the values, we had to make copies of one of the values to a temporary register to use for the comparison. This worked fine for the unsigned division algorithm. With the two's complement algorithm, though, we quickly ran out of data registers to store all of the values. We decided that the simplest way to do this was to add a new instruction. We assigned the opcode "10000" to be a sign comparison of two numbers. It does not change the value of either of the registers, but sets the Flags register to:

With this instruction, we could perform different actions if both were positive, both were negative, or the signs were different. If both values were zero (positive OR negative) then neither flag was set (equivalent to both being positive).

The only problem we had with the assembler was with using labels to jump to a later location in the program. To accomplish this, we had to initialize two token readers to go through the file. The first looked only for labels, while the second converted the assembly code into a .mif file.