# Pages Yixuan Qiu’s Home CS232 Yixuan's CS232 Project 8

1. Summary

In this project, I wrote a 2-pass assembler that converts a set of instructions written in a simple mnemonic language into machine code for the CPU I built in project 7.

The first pass of an assembler figures out what line number corresponds to each symbol that are used by branching operationsThe second pass takes in the tokens and the label dictionary, generates the set of machine instructions, and fills in the address values for branch instructions from the symbol table.

I tested my assembler using the assembly version of the program.mif file from last week:

The output MIF file is

which is identical to the program.mif file.

#### Write a fibonacci sequence program in assembly

I wrote a fib.txt file which holds the assembly version of the program that generates the first ten numbers of the fibonacci sequence.

My assembler was able to translate the assembly code into machine code, as shown below. The file is identical from the original fibonacci.mif file.

Testing:

The first ten numbers are shown by oport:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34

#### Write a recursive program in assembly

I wrote a sum.txt file and converted it to sum.mif using my assembler.

The recursive program sums numbers from 1 to 6.

The assembler converted the text file into a MIF file.

Testing:

The sum is shown by oport whose final value is 21.

1 + 2 + 3 + 4 + 5 + 6 = 21

### 1) Demonstrate your programs, generated by your assembler, on the board and set up the output port so it writes to the four 7-segment displays. Use programs that test the capabilities of your CPU.

Testing fib.mif:

fib.mp4

The displays correspond to the value of RC.

Testing sum.mif:

The displays reflect the value of RB.

#### 2) Make your assembler more intelligent so that it can catch errors, tell the user what the error is, and possibly suggest corrections.

##### a. Duplicate Labels

If there are two identical labels, my assembler will catch the error.

##### b. Unknown Operation

If the operation is not in the instruction table, then the seemlier will report the error. For example, the assembler does not know the operation "output."

##### c. Unrecognized Registers

If the order of registers are flipped, my assembler will catch the error and suggest correction.

I used try and except to handle this kind of errors.

i.

For example,

the immediate value was put after the destination register whereas the right order should be movie 1 RA.

ii.

In the following example, the source register RG is not in the register fields.

iii.

The destination register RF is not in the register fields, so the assembler will report an error.

#### 3) Create some test programs that evaluate all of the CPUs capabilities.

I wrote two more test programs to test ALL the rest CPU's capabilities.

The program testBra.txt tests the remaining three branching operations(BRAZ, BRAN, BRAO).

The program testInstr.txt uses all the rest instructions.

I commented what should be executed in the text files. The results of simulation are as expected.

Testing testInstr.mif:

Testing testBra.mif:

Mike Zheng

Bruce

Labels