The MIC-1 Simulator is designed to be used in conjunction with the textbook Computer Organization by A. Tanenbaum. Tanenbaum describes a simple, microprogrammable machine the called the MIC-1. The text also describes the conventional machine level for a simple 1 register machine called the MAC-1.
The MIC-1 simulator allows you to execute MAC-1 assembly language and observe its execution at three levels (assembly instruction, machine cycle and machine subcycle). You can also add microcode to the MIC-1 control store. This page describes two types of laboratories that can be done using the MIC-1 simulator. In the first type, students write MAC-1 machine code and hand assemble it. They then use the MIC-1 as a debugger to make sure that their program is executed correctly. In the second type of laboratory students write MIC-1 microcode to add instructions to the MAC-1 assembly language.
The descriptions below assume that you have successfully downloaded the sample MIC-1 simulator, have completed the installation procedures and have run the sample program that is included in the installation.
Laboratories:
This group of assignments uses the MIC-1 simulator as a debugger. The laboratories are designed to help students understand the conventional machine level in more detail. The following exercises are independent and are arranged in increasing level of difficulty.
The MAC-1 code for this example is relatively short and simple. You can use the direct addressing instructions to implement it. However, since the loop has 100 iterations, you will have to count carefully to execute the code completely.
The MAC-1 program in this exercise accesses an array and keeps local variables on the stack.
INSP 31
LOCO 1 /* Keep the value 1 in local 2 */
STOL 2
LOCO ARRAY /* Keep address of next array element */
STOL 3 /* in local 3 */
LOCO 10 /* Initialize counter to 10 and */
STOL 4 /* keep it in local 4 */
LOOP:
PUSH /* Put counter on stack */
LODL 4 /* Put next array address in ac */
POPI /* Store counter in that array element */
ADDL 2 /* Increment array address */
STOL 3
LODL 4 /* Decrement counter */
SUBL 2
STOL 4
JZER DONE /* If counter > 0 go to loop */
JUMP LOOP
DONE:
CALL 4095
ARRAY:
.WORD 10
In this lab you will write a function to calculate the n-th Fibonacci number. The Fibonacci sequence is defined by:
f(0) = 1
f(1) = 1
f(n) = f(n-1) + f(n-2)
int getFibonnaci(int n)
{
int f0, f1, f2;
int i;
if (n < 2)
return 1;
f0 = 1;
f1 = 1;
for (i = 2; i <= n; i++) {
f2 = f1 + f0;
f0 = f1;
f1 = f2;
}
return f2;
}
Write a MAC-1 function to perform a multiply using left shift and add. The function should pop the top two operands from the stack, multiply them and push the result back on the stack. Only the lower 16 bits will be retained.
Hand assemble and run the program on the simulator to test that it works correctly. Analyze the number of cycles that it takes to execute the multiply. Compare your results with those obtained from the following solution
pop B off stack into register B
pop A off stack into register A
top_loop:
if B is zero goto done
B := B - 1
A := LSHIFT(A)
goto top_loop
done:
push A on stack
goto fetch
1111111100000000
Modify the MIC-1 control_store file to contain the
microcode for SHFT. Note: this is the encoding that used
in the solution for the
multiply instruction. You can add the LSHFT instruction
in the same way.
mac_def
file by adding the following line to the end:
ff00 ff00 0fff 1 SHFT
For laboratory check-off you will be asked to demonstrate the correctness of your microcode by running your MAC-1 program on the mic-1 simulator. Hand in your MAC-1 source, your assembled MAC-1, your filled in MIC-1 worksheet, and your MIC-1 control store.
In this exercise you will compare the efficiency of a software left shift (implemented in MAC-1 assembly language) with a hardware left (implemented as MIC-1 microcode). The left shift will only save the lower 16 bits of result. You may want to work through the multiply laboratory of Exercise III which has a worked out solution prior to doing this laboratory.
This exercise is similar to Exercise II on the left shift. An explanation of the algorithm and an analysis of it is given in the multiply solution.
control_store file to contain the
microcode for multiply developed in class:
mac_def
file by adding the following line to the end:
ff00 ff00 0fff 1 MULD