Euripides Montagne University of Central Florida (Summer 2011)

Slides:



Advertisements
Similar presentations
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 116.
Advertisements

1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 107.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 40.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 28.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 44.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 38.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 75.
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 2: Data Manipulation
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.
University of Central Florida
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Instruction Set Architecture
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Run-Time Storage Organization
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Microarchitecture Level.
Run time vs. Compile time
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
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.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
Tannenbaum Machine. Key Features Simple architecture Simple instruction set Focus on –Input -> Higher Level Language –Output -> Machine Language Addressing.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
4-1 Chapter 4 - The Instruction Set Architecture Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Cosc 2150: Computer Organization
Runtime Environments Compiler Construction Chapter 7.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
ITEC 352 Lecture 12 ISA(3). Review Buses Memory ALU Registers Process of compiling.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
4-1 4 Interpretation  Overview  Virtual machine interpretation  Case study: SVM  Case study: SVM interpreter in Java Programming Languages 3 © 2012.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
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.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
國立台灣大學 資訊工程學系 薛智文 98 Spring Run Time Environments (textbook ch# 7.1–7.3 )
CSC 8505 Compiler Construction Runtime Environments.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
©SoftMoore ConsultingSlide 1 The CPRL Virtual Machine.
Computer Architecture & Operations I
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Computer Architecture Instruction Set Architecture
Computer Architecture Instruction Set Architecture
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Introduction to Compilers Tim Teitelbaum
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Programming Languages (CS 550) Mini Language Compiler
Chapter 8 Central Processing Unit
The University of Adelaide, School of Computer Science
Topic 3-a Calling Convention 1/10/2019.
Subroutines and the Stack
Run Time Environments 薛智文
Runtime Environments What is in the memory?.
Programming Languages (CS 360) Mini Language Compiler
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

Euripides Montagne University of Central Florida (Summer 2011) COP 3402 Systems Software Euripides Montagne University of Central Florida (Summer 2011)

Virtual Machines as instruction interpreters COP 3402 Systems Software Virtual Machines as instruction interpreters

University of Central Florida Outline Virtual machines as software interpreters P-code: instruction set architecture The instruction format Assembly language Eurípides Montagne University of Central Florida

Virtual Machine: P-code The Pseudo-code machine is a software (virtual) machine that implements the instruction set architecture of a stack computer. P-code was implemented in the 70s to generate intermediate code for Pascal compilers. Another example of a virtual machine is the JVM (Java Virtual Machine) whose intermediate language is commonly referred to as Java bytecode.

The P-machine Instruction format (PM/0) The ISA of the PM/0 has 22 instructions and the instruction format has three components <op, l, m>: OP is the operation code. L indicates the lexicographical level. M depending of the opcode it indicates: - A number (instructions: LIT, INT). - A program address (instructions: JMP, JPC, CAL). - A data address (instructions: LOD, STO) - The identity of the operator OPR(i.e. OPR 0, 2 (ADD) or OPR 0, 4 (MUL)).

Virtual Machine: P- code The interpreter of the P-machine(PM/0) consists of: A store named “stack” organized as a stack. A “code” store that contains the instructions. The CPU has four registers: Register “bp” points to the base of the current activation record (AR) in the stack Register “sp” points to the top of the stack A program counter or instruction pointer (pc) An instruction register (ir).

Virtual Machine: P- code CPU STACK AR or Frame SP BP AR or Frame PC IR CODE Eurípides Montagne University of Central Florida

Activation Records (AR) What is an activation record? Activation record or stack frame is the name given to a data structure which is inserted in the stack, each time a procedure or function is called. The data structure contains information to control sub-routines program execution. AR Stack AR AR AR CODE

Activation records (AR) Stack AR Functional value Parameters AR Locals AR Return Address Dynamic Link CODE Static Link

Activation records (AR) Control Information: Return Address: Points, in the code segment, to the next instruction to be executed after termination of the current function or procedure. Dynamic Link: Points to the previous stack frame Static Link: Points to the stack frame of the procedure that statically encloses the current function or procedure Functional value Parameters Locals Return Address Dynamic Link Static Link

Activation records (AR) Functional value: Location to store the function return value. Parameters: Space reserved to store the actual parameters of the function. Locals: Space reserved to store local variables declared within the procedure. Return Address: Points, in the code segment, to the next instruction to be executed after termination of the current function or procedure. Dynamic Link: Points to the previous stack frame Static Link: Points to the stack frame of the procedure that statically encloses the current function or procedure AR Functional value Parameters Locals Return Address Dynamic Link Static Link

Instruction cycle Back to the P-machine!! The machine has two cycles known as fetch and execute. Fetch cycle: In the fetch cycle an instruction is fetch from the code store (ir  code[pc]) and the program counter is incremented by one (pc  pc + 1). Execute cycle: In this cycle ir.op indicates the operation to be executed. In case ir.op = OPR then the field ir.m is used to identified the operator and execute the appropriate arithmetic or logical instruction

P-machine ISA opcode 01 - LIT 0, M  Push constant value (literal) M onto stack 02 – OPR ( to be defined in the next slide) 03 – LOD L, M  Push from location at offset M in frame L levels down. 04 – STO L, M  Store in location at offset M in frame L levels down. 05 – CAL L, M  Call procedure at M (generates new block mark and pc = M). 06 – INC 0, M  Allocate M locals (increment sp by M), first three are SL, DL, RA. 07 – JMP 0, M  pc = M; 08 – JPC 0, M  Jump to M if top of stack element is 0 and decrement sp by one. 09 – WRT 0, 0  ( print (stack[sp]) and sp  sp – 1

P-machine ISA opcode 02 - OPR: RTN 0,0  Return operation (i.e. return from subroutine) OPR 0,1  NEG ( - stack[sp] ) OPR 0,2  ADD (sp sp – 1 and stack[sp]  stack[sp] + stack[sp + 1]) OPR 0,3  SUB (sp sp – 1 and stack[sp]  stack[sp] - stack[sp + 1]) OPR 0,4  MUL (sp sp – 1 and stack[sp]  stack[sp] * stack[sp + 1]) OPR 0,5  DIV (sp sp – 1 and stack[sp]  stack[sp] div stack[sp + 1]) OPR 0,6  ODD (stack[sp]  stack mod 2) or ord(odd(stack[sp])) OPR 0,7  MOD (sp sp – 1 and stack[sp]  stack[sp] mod stack[sp + 1]) OPR 0,8  EQL (sp sp – 1 and stack[sp]  stack[sp] = =stack[sp + 1]) OPR 0,9  NEQ (sp sp – 1 and stack[sp]  stack[sp] != stack[sp + 1]) OPR 0,10  LSS (sp sp – 1 and stack[sp]  stack[sp] < stack[sp + 1]) OPR 0,11  LEQ (sp sp – 1 and stack[sp]  stack[sp] <= stack[sp + 1]) OPR 0,12  GTR (sp sp – 1 and stack[sp]  stack[sp] > stack[sp + 1]) OPR 0,13  GEQ (sp sp – 1 and stack[sp]  stack[sp] >= stack[sp + 1])

P-machine ISA opcode 01 - LIT 0, M  sp  sp +1; stack[sp]  M; 02 – RTN 0, 0  sp  bp -1; pc  stack[sp + 3]; bp  stack[sp + 2]; 03 – LOD L, M  sp  sp +1; stack[sp]  stack[ base(L) + M]; 04 – STO L, M  stack[ base(L) + M]  stack[sp]; sp  sp -1;

P-machine ISA opcode 05 - CAL L, M  stack[sp + 1]  base(L); /* static link (SL) stack[sp + 2]  bp; /* dynamic link (DL) stack[sp + 3]  pc /* return address (RA) bp  sp + 1; pc  M; 06 – INC 0, M  sp  sp + M; 07 – JMP 0, M  pc = M; 08 – JPC 0, M  if stack[sp] == 0 then pc  M; sp  sp - 1; 09 – WRT 0, 0  print (stack[sp]); sp  sp – 1;

P-machine: Code generation Programming example using PL/0 const n = 13; /* constant declaration var i,h; /* variable declaration procedure sub; const k = 7; var j,h; begin j:=n; i:=1; h:=k; end; begin /* main starts here i:=3; h:=0; call sub; end. P-code for the program on the left 0 jmp 0 10 1 jmp 0 2 2 inc 0 5 3 lit 0 13 4 sto 0 3 5 lit 0 1 6 sto 1 3 7 lit 0 7 8 sto 0 4 9 opr 0 0 10 inc 0 5 11 lit 0 3 12 sto 0 3 13 lit 0 0 14 sto 0 4 15 cal 0 2 16 opr 0 0 /* procedure /* declaration

Running a program on PM/0 0 jmp 0 10 1 jmp 0 2 2 inc 0 5 3 lit 0 13 4 sto 0 3 5 lit 0 1 6 sto 1 3 7 lit 0 7 8 sto 0 4 9 opr 0 0 10 inc 0 5 11 lit 0 3 12 sto 0 3 13 lit 0 0 14 sto 0 4 15 cal 0 2 16 opr 0 0 code pc bp sp stack Initial values 0 1 0 0 0 0 0 0 0 jmp 0, 10 10 1 0 0 0 0 0 0 10 inc 0, 5 11 1 5 0 0 0 0 0 11 lit 0, 3 12 1 6 0 0 0 0 0 3 12 sto 0, 3 13 1 5 0 0 0 3 0 13 lit 0, 0 14 1 6 0 0 0 3 0 0 14 sto 0, 4 15 1 5 0 0 0 3 0 15 cal 0, 2 2 6 5 0 0 0 3 0| 1 1 16 2 inc 0, 5 3 6 10 0 0 0 3 0| 1 1 16 0 0 3 lit 0, 13 4 6 11 0 0 0 3 0| 1 1 16 0 0 13 4 sto 0, 3 5 6 10 0 0 0 3 0| 1 1 16 13 0 5 lit 0, 1 6 6 11 0 0 0 3 0| 1 1 16 13 0 1 6 sto 1, 3 7 6 10 0 0 0 1 0| 1 1 16 13 0 7 lit 0, 7 8 6 11 0 0 0 1 0| 1 1 16 13 0 7 8 sto 0, 4 9 6 10 0 0 0 1 0| 1 1 16 13 7 9 opr 0, 0 16 1 5 0 0 0 1 0

Virtual Machines as instruction interpreters (The End) COP 3402 Systems Software Virtual Machines as instruction interpreters (The End)