CIS 451 Lab 4: Microcode

Author: Andrew Kalafut

Objective: To gain a better understanding of microcode.

Deliverables: Submit in hardcopy the well commented microcode (ucode file) you develop along with evidence that your code works (for example, screenshots of the relevant parts of memory after your code has run). For the extra credit portion, you will need to submit your well commented test program (mem file) as well.

This project should preferably be done in groups of 2. If there are sufficient lab computers available, you may work alone.


We will be using a graphical microcode simulator called MythSim, written by Jason Vroustouris at UIC. In this lab, you will use MythSim to write microcode to implement a variety of instructions, enough to run a small program. Mythsim is not installed on the lab machines, but is a simple jar file. You can dowload it here.


Getting Started with MythSim

The MythSim hardware is simple. Take a look at the diagram on the quick reference card. The simulated machine has 1 byte words. Therefore, registers and addresses are each one byte long. However, the instruction size is not the same as the word size. The instruction is kept in two 8 bit registers, for a total of 16 bits in an instructions. Two instruction formats are supported:
Opcode (6)Ri (2)Rj (2)Rk (2)Const4 (4)
Opcode (6)Ri (2)Const8 (8)

Longer instruction formats are also possible by changing one of the instruction registers during the processing of a single instruction.

In both of these formats, Ri specifies the destination register. In the first format, Rj and Rk are the source registers for ALU operations. Only four registers are accessable this way although there are eight total registers not counting the instruction register. The others can not be specified in a machine language instruction, but are accessable through the microcode.

Download the memory file named guide.mem, and the microcode file named guide.ucode. Open these in MythSim. Now that you have a file open, you can activate other windows in Mythsim. You should open at least the Datapath, the Memory or the Memory file, and the Ucode file.

The memory file contains the memory of the machine (instruction and data memory combined). In this case, what you see are the machine language instructions to add the numbers 0, 2, 8, and 32, and store the result in r0. The ucode file contains the microcode needed to implement these opcodes. The instructions at the top labeled fetch deal with loading instructions from memory and advancing the program counter. The instructions at the bottom are the implementation of the opcodes noop, add, li, and halt.

The main window of MythSim will allow you to run a program or step through it. Step through the provided sample program until you understand how it works. If any step of the program is unclear, please ask your instructor for explanation. Notice that r6 and r7 are both written to by the provided fetch code. You will not want to rely on values staying in these registers between instructions. While you can write to r6 without any ill effects, notice that r7 is used as the program counter since this machine does not have a dedicated register for this purpose. Your branch and jump instructions should modify r7, while most other instructions probably should not.

Implementing instructions

For your assignment, you should implement several instructions, as described in the table below. The test program, test.mem, is designed to test all of these instructions. It also relies on the instructions in guide.ucode, so include those in your file as well.

Note that some of these opcodes need multiple microinstructions in order to work.
4incRi <- Rj + 1 (add 1 to Rj, store in Ri)
5sllRi <- Rj << Rk (shift Rj left a number of bits equal to the value in Rk, filling in with 0s, store the result in Ri)
6jneIf the value in Rj is not equal to the value in Rk, jump to the address in the 4 bit immediate.
7loadRi <- Mem[Rj] (load value into Ri from memory address stored in Rj.
8storeMem[Rj] <- Rk (store value from Rk into memory address stored in Rj.

Extra credit

For one lab point extra credit (to make up a point lost on other labs), design an instruction which adds two 8 bit immediates (ignoring any overflow), and stores the result in Ri. Design your own test program.