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.
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.
.mainTo 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.
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
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.
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.