©SoftMoore ConsultingSlide 1 The CPRL Virtual Machine.

Slides:



Advertisements
Similar presentations
Euripides Montagne University of Central Florida (Summer 2011)
Advertisements

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.
Instruction Set Design
INSTRUCTION SET ARCHITECTURES
There are two types of addressing schemes:
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
Instruction Set Architecture
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
TK 2633 Microprocessor & Interfacing
Execution of an instruction
CS 536 Spring Run-time organization Lecture 19.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Run-time Environment and Program Organization
Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.
Computer Architecture
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
Compiler Construction Lecture 17 Mapping Variables to Memory.
An Introduction to 8086 Microprocessor.
Runtime Environments Compiler Construction Chapter 7.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.
4-1 4 Interpretation  Overview  Virtual machine interpretation  Case study: SVM  Case study: SVM interpreter in Java Programming Languages 3 © 2012.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Execution of an instruction
Prof. Fateman CS 164 Lecture 281 Virtual Machine Structure Lecture 28.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
by Richard P. Paul, 2nd edition, 2000.
Lecture 04: Instruction Set Principles Kai Bu
Addressing Modes MTT CPU08 Core Motorola CPU08 ADDRESSING MODES.
Ass Prof Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 6: Control Instructions.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
4-1 Embedded Systems C Programming Language Review and Dissection II Lecture 4.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Subroutines and Stacks. Stack The stack is a special area in memory used by the CPU to store register information or general data information during program.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Programming Model CS 333 Sam Houston State University Dr. Tim McGuire.
RealTimeSystems Lab Jong-Koo, Lim
01 – Overview of Compilers
Displacement (Indexed) Stack
Overview of Instruction Set Architectures
William Stallings Computer Organization and Architecture 6th Edition
Computer Architecture Instruction Set Architecture
The Stack.
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Java package classes Java package classes.
Run-time organization
Alvaro Mauricio Peña Dariusz Niworowski Frank Rodriguez
A Closer Look at Instruction Set Architectures
William Stallings Computer Organization and Architecture 8th Edition
Computer Organization and Assembly Language (COAL)
In this lecture Global variables Local variables System stack
ECEG-3202 Computer Architecture and Organization
by Richard P. Paul, 2nd edition, 2000.
Introduction to Micro Controllers & Embedded System Design
Computer Architecture
A Closer Look at Instruction Set Architectures Chapter 5
CPU has 6 special locations called registers
8051 ASSEMBLY LANGUAGE PROGRAMMING
Basic components Instruction processing
CSC 497/583 Advanced Topics in Computer Security
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

©SoftMoore ConsultingSlide 1 The CPRL Virtual Machine

©SoftMoore ConsultingSlide 2 CPRLVM (Compiler PRoject Language Virtual Machine) CPRLVM –is a hypothetical computer designed to simplify the code generation phase of a compiler for CPRL –uses a stack architecture; i.e., most instructions either expect values on the stack, place results on the stack, or both –has 4 internal or special purpose registers, but no general purpose registers Memory is organized into 8-bit bytes. Each byte is directly addressable. A word is a logical grouping of 4 consecutive bytes in memory. The address of a word is the address of its first (low) byte.

©SoftMoore ConsultingSlide 3 Representing Primitive Types Boolean values are represented in a single byte. –0 means false. –Any nonzero value is interpreted as true. Character values (Unicode) use 2 bytes. Integer values use a word (32-bit 2’s complement)

©SoftMoore ConsultingSlide 4 CPRLVM Instructions All CPRLVM instruction operation codes (opcodes) occupy one byte of memory. Some instructions take one or two one-word arguments, which are always located in the words immediately following the instruction in memory. Most instructions get their operands from the stack. In general, the operands are removed from the stack whenever the instruction is executed, and any results are left on the top of the stack.

©SoftMoore ConsultingSlide 5 Examples: CPRLVM Instructions ADD : Remove two integers from the top of the stack and push their sum back onto the stack. INC : Add 1 to the integer at the top of the stack. LOADW (load word): Load/push a word (four consecutive bytes) onto the stack. The address of the first byte of the word is obtained by popping it off the top of the stack. LDMEM (load memory address): Load/push the contents of a memory address onto the top of the stack.

©SoftMoore ConsultingSlide 6 Registers Four 32-bit internal registers (no general-purpose registers) PC (program counter; a.k.a. instruction pointer) - holds the address of the next instruction to be executed. SP (stack pointer) - holds the address of the top of the stack. The stack grows from low-numbered memory addresses to high-numbered memory addresses. SB (stack base) – holds the address of the bottom of the stack. When a program is loaded, SB is initialized to the address of the first free byte in memory. BP (base pointer) - holds the base address of the subprogram currently being executed.

©SoftMoore ConsultingSlide 7 Program Loaded in Memory Program Code Variable Stack Free Space (Unused Memory) PC BP SP SB Low-numbered memory addresses High-numbered memory addresses Stack grows in this direction

Variable Addressing Using the SB and BP Registers Variables declared at program scope are addressed relative to the SB register. Variables declared at subprogram scope are addressed relative to the BP register. Example: If SB has the value 112, and program scoped variable x has the relative address 8, then the actual address of x is [SB] + relAddr(x) or 120. When preparing for code generation, the compiler needs to determine the relative address of every variable. For programs that don’t have subprograms, both SB and BP will point to the same memory location. ©SoftMoore ConsultingSlide 8

Opcodes LDGADDR and LDADDR LDGADDR n –load global address for variable at offset n –pushes SB + n onto the stack –used for variables declared at program scope LDADDR n –load address for variable at offset n –pushes BP + n onto the stack –used for variables declared at subprogram scope ©SoftMoore ConsultingSlide 9

©SoftMoore ConsultingSlide 10 CPRL Example declare var m, n : Integer; var c : Char; const five := 5; begin m := 7; n := five*m; c := 'X'; writeln "n = ", n; writeln "c = ", c; end.

CPRL Example Disassembled 0: PROGRAM 10 5: LDGADDR 0 10: LDCINT 7 15: STOREW 16: LDGADDR 4 21: LDCINT 5 26: LDGADDR 0 31: LOADW 32: MUL 33: STOREW 34: LDGADDR 8 39: LDCCH 'X' 42: STORE2B 43: LDCSTR "n = " 56: PUTSTR 57: LDGADDR 4 62: LOADW 63: PUTINT 64: PUTEOL 65: LDCSTR "c = " 78: PUTSTR 79: LDGADDR 8 84: LOAD2B 85: PUTCH 86: PUTEOL 87: HALT ©SoftMoore ConsultingSlide 11 m: relative address = 0, absolute address = 88 n: relative address = 4, absolute address = 92 c: relative address = 8, absolute address = 96

©SoftMoore ConsultingSlide 12 Loading a Program The object code is loaded into the beginning of memory Register PC is initialized to the address of the first instruction Registers SB and BP are initialized to the address following the last instruction. Register SP is initialized to BP - 1. The first instruction, program n, allocates n bytes on the top of the stack for local variables

©SoftMoore ConsultingSlide 13 CPRL Example in Memory (after execution of first instruction) m: relative address = 0 0 BP SP … SB 97 machine instructions for the program n: relative address = 4 c: relative address = 8 … unused memory PC PROGRAM LDADDR HALT 10