Computer Architecture, First Course
Microprogramming of simulated processor
The aim of this lab is to understand how microcode can be used for executing machine instructions within a processor.
1. Background
In chapter 4 in the course literature (Structured Computer Organization, 4ed) an example microarchitecture is described. The described processor can execute programs written in a subset of the JAVA virtual machine (IJVM). A simulator, mic-1, is used for running the code. We will use the simulator in this lab. The simulator can easily be run on the Sun workstations by typing the following in your home directory:
mkdir mic1 cd mic1 tar xvfz /it/kurs/dark/mic1.tar.gz export CLASSPATH=$PWD/classes.zip
It is necessary to read chapter 4.1 - 4.3 carefully before you start the lab.
2. Exercises
The lab contains two parts:
2.1. Part 1
Write a small program in IJVM (edit a *.jas file) that lets the user write a sentence in the simulator input window and counts the number of letters typed. Spaces should not be counted. This is similar to part 5 and 6 in the mic1 user guide.
Hints: Look at echo.jas that is part of the mic1 distribution... If you want to print the result in the simulator (instead of just looking in a register), you can borrow/steal the print function provided in the add.jas file in the distribution and call it using INVOKEVIRTUAL. It prints the result in hexadecimal form.
2.2. Part 2
Implement and test a new macro instruction that multiplies two unsigned integers between 0 and 65535 (16 bit). The new instruction, called IMUL, should multiply the two top values of the stack, remove them, and return the result on top of the stack. You should ask the user for two numbers, receive them, multiply them and print the output. You can use the methods getnum and print in the file add.jas for input and output (both in hexadecimal!). For the implementation of IMUL, one can add "x" to itself "y-1" times to compute "x * y". However that is unefficient for large numbers. Instead you should use the classic method:
110 (6) 101 (5) ----- 110 000 110 ------ 11110 (30)
This method requires that you are able to add and shift numbers. The problem is that the provided micro instructions can only shift by 8 to the left or 1 to the right. We would like to shift by 1 to the left. This can be done by adding the number to itself, for example: 110+110=1100 (6+6=12). If you want to shift a given number of bits to the left, let say n steps, you can put n in MDR and perform:
imul1 ....... imul2 MDR = MDR - 1 imul3 OPC = H = H + OPC imul4 Z = MDR; if (Z) goto imul5; else goto imul2 imul5 .......
You should insert your micro code in the file mic1ijvm.mal with 0x78 as the control store address. Compile mic1ijvm.mal with mic1asm and update the ijvm.conf file.
To implement this in micro code, you have to access the memory via the stack. Try to use the memory as little as possible; use the registers instead.
3. Verification
Verify the multiplicator so that you are convinced that it works as intended. Write down (in at least half a page) an account of how you verified it and be prepared to defend your position that this verification is enough evidence that your solution is correct.
In the previous digital logic exercise (not mandatory for the 4p course), one obvious verification technique was to test all possible multiplications. This is (probably) not possible here since the number of combinations is very large. How many different multiplications do you think it reasonable to test? The written record should explain exactly which cases were tested and argue why these are enough.
4. Presentation
The presentation will be oral. However, it is important that you bring printouts of all the code and answers you have written to the presentation.