Prof. Fateman CS 164 Lecture 201 Virtual Machine Structure Lecture 20.

Slides:



Advertisements
Similar presentations
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Advertisements

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Coalescing Register Allocation CS153: Compilers Greg Morrisett.
INSTRUCTION SET ARCHITECTURES
Princess Sumaya Univ. Computer Engineering Dept. Chapter 2: IT Students.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
Procedures in more detail. CMPE12cGabriel Hugh Elkaim 2 Why use procedures? –Code reuse –More readable code –Less code Microprocessors (and assembly languages)
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
Systems Architecture Lecture 5: MIPS Instruction Set
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
1 Computer Architecture MIPS Simulator and Assembly language.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
Procedures in more detail. CMPE12cCyrus Bazeghi 2 Procedures Why use procedures? Reuse of code More readable Less code Microprocessors (and assembly languages)
1 Handling nested procedures Method 1 : static (access) links –Reference to the frame of the lexically enclosing procedure –Static chains of such links.
CS 536 Spring Run-time organization Lecture 19.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
CS 536 Spring Code generation I Lecture 20.
Intro to Computer Architecture
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Run time vs. Compile time
CS 300 – Lecture 19 Intro to Computer Architecture / Assembly Language C Coding & The Simulator Caches.
More on FunctionsCS-2301 B-term More on Functions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming Language,
Intermediate Code. Local Optimizations
Prof. Fateman CS164 Lecture 211 Local Optimizations Lecture 21.
4/6/08Prof. Hilfinger CS164 Lecture 291 Code Generation Lecture 29 (based on slides by R. Bodik)
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
Prof. Fateman CS 164 Lecture 191 Introduction to Intermediate Code, virtual machine implementation Lecture 19.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Compiler Construction Lecture 17 Mapping Variables to Memory.
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
CS41B MACHINE David Kauchak CS 52 – Fall Admin  Midterm Thursday  Review question sessions tonight and Wednesday  Assignment 3?  Assignment.
1 CS232: Computer Architecture II Fall 2011 Intel i7 Quad-core.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Prof. Fateman CS 164 Lecture 281 Virtual Machine Structure Lecture 28.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
EEL5708/Bölöni Lec 8.1 9/19/03 September, 2003 Lotzi Bölöni Fall 2003 EEL 5708 High Performance Computer Architecture Lecture 5 Intel 80x86.
1 CS232: Computer Architecture II Fall 2010 AMD dual-core Opteron.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
CS232: Computer Architecture II
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
Section 5: Procedures & Stacks
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS216: Program and Data Representation
Run-time organization
A Closer Look at Instruction Set Architectures
Introduction to Compilers Tim Teitelbaum
The University of Adelaide, School of Computer Science
Assembly Programming using MIPS R3000 CPU
CS 11 C track: lecture 8 Last week: hash tables, C preprocessor
Java Byte Codes (0xCAFEBABE) cs205: engineering software
Systems Architecture Lecture 5: MIPS Instruction Set
These are slides from Comp411
Lecture 30 (based on slides by R. Bodik)
The University of Adelaide, School of Computer Science
Introduction to Intermediate Code, virtual machine implementation
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Assembly Programming using MIPS R3000 CPU
The C Language: Intro.
August 31 addresses Drop box Questions? 31 August 2004
Presentation transcript:

Prof. Fateman CS 164 Lecture 201 Virtual Machine Structure Lecture 20

Prof. Fateman CS 164 Lecture 202 Basics of the MJ Virtual Machine Word addressed (in many other machines we are forever shifting by 2 bits to get from words to bytes or back.) All instructions (appear to) fit in a single word. All integers fit in a single word. Everything else is “pointed to” and all pointers fit in a single word. A minimum set of operations for MJ, but these could be expanded easily. All arithmetic operations use a stack.

Prof. Fateman CS 164 Lecture 203 Why a stack? The usual alternative is: a pile of registers. Why use registers in IC? Many, (all?) current architectures have registers. If you want to control efficiency, you need to know how to save/restore/spill registers. It is not too hard, if you have enough of them. Why use a stack? Some architectures historically were stack-dependent because they had few registers (like 4, or 16..). Some current architectures use a stack e.g. for floats in Pentium, 8 values. Minimize complexity for code generation.

Prof. Fateman CS 164 Lecture 204 Why a stack? Are registers more work for IC? Generating code to load data into registers initially seems more complicated, Not by much: the compiler can keep track of which register has a value [perhaps by keeping a stack of variable-value pairs while generating code], And you did this in CS61c, but in your head, probably. With a finite number of registers there is always the possibility of running out: “spill” to a stack? Or… (New architectures with 128 registers or more make running out unlikely but then what?: perhaps “error, expression too complicated, compiler fails”?). Opportunity to optimize: rearrange expressions to use minimum number of registers. Good CS theory problem related to graph coloring. (In practice, registers are finicky, aligned, paired, special purpose,…)

Prof. Fateman CS 164 Lecture 205 Instructions: stack manipulation pushi x push immediate the constant x on the top of the stack used only for literals. Same as iconst. e.g. (iconst 43) Only 24 bits for x(?). (larger consts in 2 steps??) pusha x push address. pushes the address of x on stack. e.g. pusha ="hello world". We assume the assembler will find some place for x. Same as sconst. e.g. (sconst "hello") pop pops top of stack; value is lost dup pushes duplicate of top of stack swap guess

Prof. Fateman CS 164 Lecture 206 A simple call / the thinking.. Consider a method public int function F(){return 3; /*here*/ } How might we compile F() ? Set up a label L001 for location /*here*/. Save it on the stack. Push the address of F on the stack. Execute a (callj 0) to call F, a function of 0 args Execute an (args 0) /* get params, here none {what about THIS}*/ the stack looks like L001 3 Execute a (return). Which jumps to L001, leaving 3 on the stack. (exit 0)

Prof. Fateman CS 164 Lecture 207 A simple call/ the program public int function F(){return 3; /*here*/ } (save L001) (lvar 1 0) // magic… get address of f on stack.. Details follow (callj 0) // call function of 0 args L001: // label to return to (exit 0) The program f looks like (args 0) // collect 0 arguments into environment.. (pushi 3) (return)

Prof. Fateman CS 164 Lecture 208 More fun, less work, look at SCAM (setf *fact-test* (compile-scam '( (define (main) (print (factorial 5))) (define (factorial n) (if n (* n (factorial (- n 1))) 1)))))

Prof. Fateman CS 164 Lecture 209 More fun, less work, look at SCAM (setf *fact-test* (compile-scam '( (define (main) (print (factorial 5))) (define (factorial n) (if n (* n (factorial (- n 1))) 1))))) (pprint-code *fact-test*) (run-vm (make-vm-state :code (assemble *fact-test*)))