Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIC-1 SIMULATOR Programming in IJVM

Similar presentations


Presentation on theme: "MIC-1 SIMULATOR Programming in IJVM"— Presentation transcript:

1 MIC-1 SIMULATOR Programming in IJVM
Computer Architecture Jim Skon

2 Topics Mic-1 simulator programming Reverse Polish notation
Programming assignment on Moodle Reverse Polish notation Assembly language IJVM instruction set

3 Using the Mic-1 Simulator
Runs as a Java Application Simulates a simplified version of the Java Virtual Machine. Can be Downloaded from Moodle. Two Versions High resolution Low resolution

4 Using the Mic-1 Simulator
Write IJVM “.jas” files using an editor – ( Start the Mic-1 simulator Load and Assemble the “.jas” file using the IJVM assembler. Use the “File/Assemble/ Load JAS file.” This creates machine code. Program is ready to run. Example: acsii.jas Prints all characters!

5 Reverse Polish Notation (RPN)
Method to write arithmetic expressions Avoids the use of brackets to define priorities for evaluation of operators Devised by Jan Lucasiewicz Polish philosopher and mathematician In his notation, the operators preceded their arguments The “reverse” places operators after arguments For more info stone.ch.cam.ac.uk/documentation/rrf/rpn.ht ml tation

6 RPN Example (3 + 5) * (7 -2) Add 3 to 5 Then, subtract 2 from 7
Finally, multiply the two results together Using RPN notation: *

7 RPN Example – Stack based
* (read from left to right) Push 3 onto stack Push 5 onto the stack – The stack now contains (3, 5) Use “+” operator – Pop two numbers from stack and push result (8) Push 7 onto the stack Push 2 onto the stack – The stack now contains (8, 7, 2) Use “-” operator – Pop two numbers from stack and push result (5) Use “*” operator – Pop two numbers from stack and push result (40)

8 RPN Example – IJVM Code BIPUSH 3
BIPUSH 5 – The stack now contains (3, 5) IADD – Pop two numbers from stack and push result (8) BIPUSH 7 BIPUSH 2 – The stack now contains (8, 7, 2) ISUB – Pop two numbers from stack and push result (5) IMUL – Pop two numbers from stack and push result (40)

9 Structured Computer Organization
Digital logic builds microarchitecture Microarchitecture implements the ISA ISA is in machine language Assembly language allows us to use ISA

10 Assembly Language Uses symbolic names (mnemonics) and symbolic addresses (variables) for the machine language An assembler converts the assembly language into machine language Each statement produces exactly one machine instruction (1:1 mapping)

11 Why Use Assembly? Versus machine language Versus high-level language
Easier to remember mnemonics for instructions instead of corresponding machine language Easier to work with the symbolic addresses instead of numerical values of address Versus high-level language Access: has access to all features and instructions of the ISA Performance: Code produced can be much smaller (for low-memory devices) and faster (for speed-critical functions)

12 Undocumented Assembler Instructions
ARG : Agree to Run Garbage BDM : Branch and Destroy Memory CMN : Convert to Mayan Numerals DDS : Damage Disk and Stop EMR : Emit Microwave Radiation ETO : Emulate Toaster Oven FSE : Fake Serious Error GSI : Garble Subsequent Instructions GQS : Go Quarter Speed HEM : Hide Evidence of Malfunction IDD : Inhale Dust and Die IKI : Ignore Keyboard Input

13 IJVM Instruction Set

14 IJVM Instruction Set

15 Exercise Write IJVM assembly code for the following C++ code:
int x = 0; for (int i = 0; i < 20; i++) x+= i;

16 Basic Program Format .main // all variables declared within .varand .end-var .var x i .end-var // Main program goes next // Program execution is terminated with a HALT statement // See next slide for exercise solution .end-main

17 Solution to Previous Exercise
BIPUSH 0 ISTORE x ISTORE I L1: BIPUSH 19 ILOAD i ISUB IFLT L2 ILOAD x IADD IINC i 1 GOTO L1 L2: HALT

18 Input and Output IN OUT Reads a character from the key buffer
Pushes its value onto the stack If no key has been pressed, zero will be pushed onto the stack OUT Pops a word off the stack Prints it to the standard output text area Can only output ASCII values

19 Getting a Character from Keyboard
GOTO getch L0: ISTORE z HALT getch: IN DUP IFEQ reread GOTO L0 reread: POP

20 Assignment Get the ascii.jas, sum.jas, and echo.jas programs to all work. Write a program to read in a two digit number, and sum the even numbers from 2 to that number. Extra credit if you can print out the answer.


Download ppt "MIC-1 SIMULATOR Programming in IJVM"

Similar presentations


Ads by Google