CS 220 - Lab 6: The Microarchitecture Level
Due November 10, 2003

General Lab Goals

This lab provides an opportunity to explore the Microarchitecture level of computer organization.  Following the Mic-1 model described in Chapter 4 of your text, we introduce and exercise a Mic-1 simulator in the Mac lab.  We then trace the translation of an actual Java program from its source to an assembly language program, an IJVM program, and finally to a series of microinstructions that drive the Mic-1 architecture to compute the results.

1. Exercise the Mic-1 Simulator

The Mic-1 simulator mic1sim is available in the folder CS220 (Tucker) -> mic-1.  Drag a copy of that folder to the desktop, open the folder mic-1 -> mic1simulator, and double click on the application mic1sim. This should show the following window on the screen.

This simulator runs IJVM bytecode programs like echo.ijvm, which appears in the same folder.  To run a program:

1.  Select File -> Load Microprogram and then type mic1ijvm.mic1.  This loads the microcode that will configure the machine as an IJVM bytecode interpreter.

2.  SelectFile -> Load Macroprogram and then type echo.ijvm in the dialog box that appears.  Now select theRun button.  Every keystroke that you type while the program is running will appear in the Standard out window of the simulator.

Now stop the program and select the Step button several times.  Every Step simulates the execution of a single microinstruction.  Notice that the MPC changes every time this button is selected, while the PC changes only after several steps.  This reflects the fact that each macroinstruction (IJVM instruction) requires several microinstructions to completely execute.  The meanings of the registers (MAR, MDR, etc) and the Microinstructions that you see during this activity are the same ones described in Chapter 4 of your text.

Now load the macroprogram add.ijvm, select the Reset and Run buttons.  Notice that typing two hexadecimal numbers in the Standard out window will yield (after some delay) their Hex sum in that window.

Note that to run a program on the simulator, it must be translated into Mic-1 machine language, or bytecode.  This form is identified by the suffix .ijvm on the program name.  More details of the Mic-1 simulator can be found in the document mic1 User Guide.

2. Writing and Assembling IJVM Assembly Language Programs

We can write programs for Mic-1 at either of two levels: microassembly language (they have the suffix .mal) or IJVM assembly language (they have the suffix .jas).

For the moment, we'll consider only IJVM assembly language programs.  Once such a program is written it must be translated into bytecode, using assembler ijvmasm, which is in the folder Mic-1 -> ijvmassembler

Below is the text of the sample IJVM assembly language program called echo.jas.  Note that it has instructions like the sampel IJVM programs discussed in Chapter 4 of your text.

.main

L1:   IN           // request character input from memory
      DUP          // duplicate top of stack (inputed char) for comparing
      BIPUSH 0x0   // push 0x0 for comparison
      IF_ICMPEQ L2 // if no characters are available for input, loop
      OUT          // else, print character
      GOTO L1      // loop back to beginning of program

L2:   POP          // No key has been pushed, so clear the stack,
      GOTO L1      // and start over
.end-main
To translate this program to bytecode, double-click on the assembler ijvmasm in the folder on the desktop, and specify echo.jas as the source program in the File menu.  Now select compile, and the bytecode file echo.ijvm will be created.  Once created, the bytecode file should be dragged to the mic1simulator folder before it can be run by the Mic-1 simulator.

Below is another IJVM program, which displays all the printable ASCII values 32..126.

.constant
one     1
start   32
stop    126
.end-constant

.main
        LDC_W start
next:   DUP
        OUT             // output the current character
        DUP
        LDC_W stop
        ISUB
        IFEQ done       // exit if we've reached the end
        LDC_W one
        IADD
        GOTO next       // increment and do the next one
done:   POP
        HALT
.end-main

For practice, copy and paste it into the text file ascii.jas, and save the file in the ijvmasm folder on the desktop.  Now compile this program, obtaining the bytecode file ascii.ijvm, and drag this new file to the mic1sim folder and run it.  The Standard out window should display all the printable ASCII characters.

More information about the details of writing IJVM Assembly Language programs can be found in the document IJVM Assembly Language Specification.

3.  Running the Mic-1 Simulator in the Linux Lab

Make a copy of the directory /home/allen/mic1 in your own Linux directory.  There are subdirectories called mic1simulator and mic1assembler that contain the software described above.  In Linux, this software runs as a Java program, so at the prompt you type:

% java mic1sim                                          to start the simulator from the directory mic1simulator
% java mic1asm <filename>.ijvm          to start the assembler from the directory mic1assembler

Additional details of running programs in Linux will be introduced as we go.  You may complete this lab using either a Linux machine or an iMac.

4.  A Programming Task

Using this model, adapt the echo.jas program so that it displays a user-typed message both in ALL CAPS and in all lower case.  All user-typed characters that are not letters of the alphabet should be displayed as they appear.  For instance, if the user types "I have 3 wishes." in one column, the Standard out window should display "I HAVE 3 WISHES." in the second column and "i have 3 wishes." in the third.

Hint: Recall that the ASCII characters are represented as 8-bit values in which the uppercase equivalent of a lowercase letter differs from that letter only in the third bit position. For instance, the lowercase letter "e" has the ASCII binary value 01100101, while the uppercase "E" has the value 01000101.  Capitalization (or uncapitalization) can thus be viewed as a logical "and" (or logical "or") operation.

Hand In:

By 5pm on the due date, submit a printout of your completed program lab6yourname.jas from Part 4, along with the answers to the following questions from page 299 in your text:  4, 7, 9, 11, 15, 16, 17.