MIC-1 SIMULATOR Programming in IJVM

Slides:



Advertisements
Similar presentations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Advertisements

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Chapter 4 - MicroArchitecture
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Lab 9 Java Bytecode & The Jasmin Assembler
Computer Architecture I - Class 9
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Procedure calls (1) The fact: Most programming languages support the concept of procedures (methods). Each method has its own local variables that are.
Mic-1: Microarchitecture University of Fribourg, Switzerland System I: Introduction to Computer Architecture WS January 2006
Consider With x = 10 we may proceed as (10-1) = 9 (10-7) = 3 (9*3) = 27 (10-11) = -1 27/(-1) = -27 Writing intermediates on paper.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
1 Lab Session-IV CSIT-120 Fall 2000 Precedence Rules Machine Language Programming The “Micro” Machine The “Micro” Simulator The “Micro” Translator (Thanks.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Implementation of a Stored Program Computer
Lecture 18 Last Lecture Today’s Topic Instruction formats
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Topics Introduction Hardware and Software How Computers Store Data
High-Level Programming Languages: C++
CIS Computer Programming Logic
Krakatoa: Decompilation in Java “Does Bytecode Reveal Source?” Todd A. Proebsting Scott A. Watterson The University of Arizona Presented by Karl von Randow.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
4-1 Chapter 4 - The Instruction Set Architecture Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
1 Introduction to JVM Based on material produced by Bill Venners.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
The Microarchitecture Level
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues (part 2)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Microarchitecture Level.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
The Micro Architecture Level
Review on Program Challenge CSc3210 Yuan Long.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
RealTimeSystems Lab Jong-Koo, Lim
Fundamentals of Programming I Overview of Programming
ECE 103 Engineering Programming Chapter 5 Programming Languages
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Topics Introduction Hardware and Software How Computers Store Data
Chapter 2 - Introduction to C Programming
Microprocessor Systems Design I
CS216: Program and Data Representation
Additional Assembly Programming Concepts
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Chapter 2 - Introduction to C Programming
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
The Instruction Set Architecture Level
Chapter 2 - Introduction to C Programming
Topics Introduction Hardware and Software How Computers Store Data
Chapter 2 - Introduction to C Programming
Computer Architecture
Instructions in Machine Language
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
Chapter 2 - Introduction to C Programming
A Level Computer Science Topic 5: Computer Architecture and Assembly
Introduction to C Programming
Presentation transcript:

MIC-1 SIMULATOR Programming in IJVM Computer Architecture Jim Skon

Topics Mic-1 simulator programming Reverse Polish notation http://www.ontko.com/mic1/ Programming assignment on Moodle Reverse Polish notation Assembly language IJVM instruction set

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

Using the Mic-1 Simulator Write IJVM “.jas” files using an editor – (www.textpad.com) 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!

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 http://www- stone.ch.cam.ac.uk/documentation/rrf/rpn.ht ml http://en.wikipedia.org/wiki/Reverse_Polish_No tation

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

RPN Example – Stack based 3 5 + 7 2 -* (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)

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)

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

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)

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)

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

IJVM Instruction Set

IJVM Instruction Set

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

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

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

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

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

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.