Virtual Machine I: Stack Arithmetic
|
|
- Geoffrey Small
- 6 years ago
- Views:
Transcription
1 Virtul Mchine I: Stck Arithmetic Building Modern Computer From First Principles Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 1
2 Where we re t: Humn Thought Abstrct design Chpters 9, 12 bstrct interfce H.L. Lnguge & Operting Sys. Compiler Chpters bstrct interfce Virtul Mchine Softwre hierrchy VM Trnsltor Chpters 7-8 bstrct interfce Assembly Lnguge Assembler Chpter 6 bstrct interfce Mchine Lnguge Computer Architecture Chpters 4-5 Hrdwre hierrchy bstrct interfce Hrdwre Pltform Gte Logic Chpters 1-3 bstrct interfce Chips & Logic Gtes Electricl Engineering Physics Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 2
3 Motivtion clss clss Min Min { { sttic sttic int int x; x; function function void void min() min() { { // // Input Input nd nd multiply multiply 2 2 numbers numbers vr vr int int,, b, b, x; x; Keybord.redInt( Enter Keybord.redInt( Enter number ); number ); b b Keybord.redInt( Enter Keybord.redInt( Enter number ); number ); x x mult(,b); mult(,b); return; return; } } } } // // Multiplies Multiplies two two numbers. numbers. function function int int mult(int mult(int x, x, int int y) y) { { vr vr int int result, result, j; j; result result 0; 0; j j y; y; while while not(j not(j 0) 0) { { result result result result + + x; x; j j j j 1; 1; } } return return result; result; } } } } Ultimte gol: Trnslte highlevel progrms into executble M0 M ;JMP 0;JMP 0;JMP 0;JMP Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 3
4 Compiltion models direct compiltion: lnguge 1 lnguge 2 lnguge n 2-tier compiltion: lnguge 1 lnguge 2 lnguge n intermedite lnguge hrdwre pltform 1 hrdwre pltform 2. requires n m trnsltors hrdwre pltform m hrdwre pltform 1 hrdwre pltform 2 requires n + m trnsltors hrdwre pltform m Two-tier compiltion: 1 st compiltion stge depends only on the detils of the source lnguge 2 nd compiltion stge depends only on the detils of the trget pltform. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 4
5 The big picture VM implementtion over CISC pltforms Some lnguge Some compiler VM imp. over RISC pltforms Some Other lnguge Some Other compiler Intermedite code VM emultor Jck lnguge Jck compiler VM imp. over the Hck pltform The intermedite code: The interfce between the 2 compiltion stges Must be sufficiently generl to support mny <HLL, ML> pirs Cn be modeled s the lnguge of n bstrct virtul mchine (VM) Cn be implemented in severl different wys. CISC mchine lnguge RISC mchine lnguge written in high-level lnguge Hck mchine lnguge CISC mchine RISC mchine other digitl pltforms, ech equipped with its own VM implementtion Any computer Hck computer Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 5
6 Focus of this lecture: Some lnguge Some Other lnguge Jck lnguge Some compiler Some Other compiler Jck compiler Chpters 9-13 VM lnguge VM implementtion over CISC pltforms VM imp. over RISC pltforms VM emultor VM imp. over the Hck pltform Chpters 7-8 CISC mchine lnguge RISC mchine lnguge written in high-level lnguge Hck mchine lnguge Chpters 1-6 CISC mchine RISC mchine other digitl pltforms, ech equipped with its VM implementtion Any computer Hck computer Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 6
7 Lecture pln Gol: Specify nd implement VM model nd lnguge: Arithmetic // Boolen commnds dd dd sub sub neg neg eq eq gt gt This lecture lt lt nd nd or or not not Memory ccess commnds pop pop x (pop (pop into into x, x, which which is is vrible) vrible) push pushy (y (y being being vrible vrible or or constnt) constnt) Progrm flow flow commnds lbel (declrtion) (declrtion) goto goto (lbel) (lbel) if-goto (lbel) (lbel) Next lecture Function clling commnds function (declrtion) (declrtion) cll cll ( ( function) function) return (from (from function) function) Method: () specify the bstrction (model s constructs nd commnds) (b) propose how to implement it over the Hck pltform. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 7
8 The VM model nd lnguge Perspective: From here till the end of this nd the next lecture we describe the VM model used in the Hck-Jck pltform Other VM models (like JVM/JRE nd IL/CLR) re similr in spirit but different in scope nd detils. progrmmers re cretors of universes for which they lone re responsible. Universes of virtully unlimited complexity cn be creted in the form of computer progrms. (Joseph Weizenbum) The VM model + lnguge re n exmple of one such universe View I: the VM is mchine tht mkes sense in its own right View II: the VM is convenient in-between representtion of computer progrm: n interim sttion between the high-level code nd the mchine level code. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 8
9 Our VM is stck-oriented mchine dd 17 9 Our VM fetures single 16-bit dt type tht cn be used s: Integer Boolen Pointer Typicl opertion: Pops topmost vlues x,y from the stck Computes the vlue of some function f(x,y) Pushes the result onto the stck (Unry opertions re similr, using x nd f(x) insted) Impct: the opernds re replced with the opertion s result In generl: ll rithmetic nd Boolen opertions re implemented similrly. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 9
10 Memory ccess (first pproximtion) Stck Memory 17 push b b Stck b Memory (before) (fter) Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 10
11 Memory ccess (first pproximtion) Stck Memory 17 push b b Stck b Memory (before) (fter) Stck b Memory pop Stck b Memory Clssicl dt structure Elegnt nd powerful Severl hw/sw implementtion options. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 11
12 Evlution of rithmetic expressions // d(2-x)*(y+5) push 2 push x sub push y push 5 dd mult pop d x 5 y Memory 9 Stck push 2 2 push x 2 sub push y 9 push 5 dd mult pop d Stck x 5 y Memory 9 d -42 Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 12
13 Evlution of Boolen expressions // if (x<7) or (y8) push x push 7 lt push y push 8 eq or x 12 y Memory 8 Stck push x push 7 7 lt flse flse flse push y 8 push 8 eq 8 8 flse true or true Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 13
14 Arithmetic nd Boolen commnds (wrp-up) Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 14
15 Memory segments Modern progrmming lnguges normlly feture the following vrible kinds: Clss level Sttic vribles Privte vribles (AKA object vribles / fields / properties ) Method level: Locl vribles Argument vribles The VM bstrction must support (t lest) these vrible kinds. In our VM model, these vribles re stored in virtul memory segments Specificlly, our VM model consists of 8 memory segments: sttic, this, locl, rgument As well s: tht, constnt, pointer, nd temp. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 15
16 Memory segments nd memory ccess commnds So we hve 8 virtul memory segments: sttic, this, locl, rgument, tht, constnt, pointer, temp But, t the VM level, there is no need to differentite mong the different roles of these segments As fr s VM progrmming commnds go, segment is segment is segment; to ccess prticulr segment entry, use the syntx: Memory ccess commnd formt: pop pop segment ii push push segment ii These commnds re used insted of pop x nd push y, s shown in previous slides, which ws conceptul simplifiction The mening of the different eight segments will become importnt when we ll tlk bout the compiler. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 16
17 VM progrmming VM progrms re normlly written by compilers, not by humns But, for humn to write or optimize compiler, the humn must first understnd the spirit of VM progrmming So, here is n exmple. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 17
18 Arithmetic exmple High-level code function function mult mult (x,y) (x,y) { int int result, result, j; j; result result 0; 0; j y; y; while while ~(j ~(j 0) 0) { result result result result + x; x; j j - 1; 1; } return return result; result; } Just fter mult(7,3) is entered: Stck rgument locl 0 7 Just fter mult(7,3) returns: Stck x 0 y 1 0 sum 0 j VM code (first pprox.) function function mult(x,y) mult(x,y) push push 0 pop pop result result push push y pop pop j lbel lbel loop loop push push j push push 0 eq eq if-goto if-goto end end push push result result push push x dd dd pop pop result result push push j push push 1 sub sub pop pop j goto goto loop loop lbel lbel end end push push result result return return VM code function function mult mult 2 push push constnt constnt 0 pop pop locl locl 0 push push rgument rgument 1 pop pop locl locl 1 lbel lbel loop loop push push locl locl 1 push push constnt constnt 0 eq eq if-goto if-goto end end push push locl locl 0 push push rgument rgument 0 dd dd pop pop locl locl 0 push push locl locl 1 push push constnt constnt 1 sub sub pop pop locl locl 1 goto goto loop loop lbel lbel end end push push locl locl 0 return return Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 18
19 Lecture pln Gol: Specify nd implement VM model nd lnguge Arithmetic // Boolen commnds dd dd sub sub neg neg eq eq gt gt This lecture lt lt nd nd or or not not Memory ccess commnds pop pop segment i push pushsegment i Progrm flow flow commnds lbel (declrtion) (declrtion) goto goto (lbel) (lbel) if-goto (lbel) (lbel) Next lecture Function clling commnds function (declrtion) (declrtion) cll cll ( ( function) function) return (from (from function) function) Method: () specify the bstrction (model s constructs nd commnds) (b) propose how to implement it over the Hck pltform. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 19
20 Implementtion VM implementtion options: Softwre-bsed (emulte the VM using, sy, Jv) Trnsltor-bsed (trnslte VM progrms into, sy, the Hck lnguge) Hrdwre-bsed (relize the VM using dedicted memory nd registers) Well-known trnsltor-bsed implementtions: JVM (runs bytecode progrms in the Jv pltform) CLR (runs IL progrms in the.net pltform). Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 20
21 Our VM emultor (prt of the course softwre suite) Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 21
22 Stndrd VM implementtion on the Hck pltform TEMP Generl purpose LCL ARG THIS THAT Host RAM Sttics Stck Hep The chllenge: (i) mp the VM constructs on the host RAM, nd (ii) given this mpping, figure out how to implement ech VM commnd using ssembly commnds tht operte on the RAM locl,rgument,this,tht: mpped on the hep. The bse ddresses of these segments re kept in LCL,ARG,THIS,THAT. Access to the i-th entry of segment is implemented by ccessing the segment s (bse + i) word in the RAM sttic: sttic vrible number j in VM file f is implemented by the ssembly lnguge symbol f.j (nd recll tht the ssembler mps such symbols to the RAM strting from ddress 16) constnt: truly virtul segment: Access to constnt i is implemented by supplying the constnt i pointer: used to lign this nd tht with memory blocks on the hep Exercise: given the bove gme rules, write the Hck commnds tht implement, sy, push constnt 5 nd pop locl 2. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 22
23 Proposed VM trnsltor implementtion: Prser module Prser: Hndles the prsing of single.vm file, nd encpsultes ccess to the input code. It reds VM commnds, prses them, nd provides convenient ccess to their components. In ddition, it removes ll white spce nd comments. Routine Arguments Returns Function Constructor Input file / strem -- Opens the input file/strem nd gets redy to prse it. hsmorecommnds -- boolen Are there more commnds in the input? dvnce Reds the next commnd from the input nd mkes it the current commnd. Should be clled only if hsmorecommnds() is true. Initilly there is no current commnd. commndtype -- C_ARITHMETIC, C_PUSH, C_POP, C_LABEL, C_GOTO, C_IF, C_FUNCTION, C_RETURN, C_CALL Returns the type of the current VM commnd. C_ARITHMETIC is returned for ll the rithmetic commnds. rg1 -- string rg2 -- int Returns the first rgument of the current commnd. In the cse of C_ARITHMETIC, the commnd itself (dd, sub, etc.) is returned. Should not be clled if the current commnd is C_RETURN. Returns the second rgument of the current commnd. Should be clled only if the current commnd is C_PUSH, C_POP, C_FUNCTION, or C_CALL. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 23
24 Proposed VM trnsltor implementtion: CodeWriter module CodeWriter: Trnsltes VM commnds into Hck ssembly code. Routine Arguments Returns Function Constructor Output file / strem -- Opens the output file/strem nd gets redy to write into it. setfilenme filenme (string) -- Informs the code writer tht the trnsltion of new VM file is strted. writearithmetic commnd (string) -- Writes the ssembly code tht is the trnsltion of the given rithmetic commnd. WritePushPop Commnd (C_PUSH or C_POP), segment (string), index (int) -- Writes the ssembly code tht is the trnsltion of the given commnd, where commnd is either C_PUSH or C_POP. Close Closes the output file. Comment: More routines will be dded to this module in chpter 8. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 24
25 Perspective Some lnguge Some compiler Some Other lnguge Some Other compiler Jck compiler VM lnguge In this lecture we begn the process of building compiler VM implementtion over CISC pltforms VM imp. over RISC pltforms CISC RISC mchine mchine lnguge lnguge VM emultor Trnsltor written in high-level lnguge Hck Modern compiler rchitecture: Front-end (trnsltes from high level lnguge to VM lnguge) Bck-end (trnsltes from the VM lnguge to the mchine lnguge of some trget hrdwre pltform) Brief history of virtul mchines: 1970 s: p-code 1990 s: Jv s JVM 2000 s: Microsoft.NET A full blown VM implementtion typiclly includes common softwre librry (cn be viewed s mini, portble OS). We will build such mini OS lter in the course. Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 25
26 The rod hed Tsks: Compe the VM specifiction nd implementtion (chpters 7,8) Introduce Jck, high-level progrmming lnguge (chpter 9) Build compiler for it (chpters 10,11) Finlly, build mini-os, i.e. run-time librry (chpter 12). Conceptully similr to: JVM Jv Jv compiler JRE And to: CLR C# C# compiler.net bse clss librry Elements of Computing Systems, Nisn & Schocken, MIT Press, Chpter 7: Virtul Mchine I: Stck Arithmetic slide 26
Virtual Machine (Part I)
Hrvrd University CS Fll 2, Shimon Schocken Virtul Mchine (Prt I) Elements of Computing Systems Virtul Mchine I (Ch. 7) Motivtion clss clss Min Min sttic sttic x; x; function function void void min() min()
More informationVirtual Machine. Part I: Stack Arithmetic. Building a Modern Computer From First Principles.
Virtual Machine Part I: Stack Arithmetic Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Chapter 7:
More informationVirtual Machine Where we are at: Part I: Stack Arithmetic. Motivation. Compilation models. direct compilation:... 2-tier compilation:
Where we are at: Virtual Machine Part I: Stack Arithmetic Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy Translator
More informationOutline CS 412/413. Function calls. Stack layout. Tiling a call. Two translations
CS 412/413 Introduction to Compilers nd Trnsltors Cornell University Andrew Myers Outline Implementing function clls Implementing functions Optimizing wy the pointer Dynmiclly-llocted structures strings
More informationOutline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers
CS 412 Introduction to Compilers Andrew Myers Cornell University Lectur8 Finishing genertion 9 Mr 01 Outline Tiling s syntx-directed trnsltion Implementing function clls Implementing functions Optimizing
More informationCPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls
Redings for Next Two Lectures Text CPSC 213 Switch Sttements, Understnding Pointers - 2nd ed: 3.6.7, 3.10-1st ed: 3.6.6, 3.11 Introduction to Computer Systems Unit 1f Dynmic Control Flow Polymorphism nd
More informationSome Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing
Undergrdute Compilers Review nd Intro to MJC Announcements Miling list is in full swing Tody Some thoughts on grd school Finish prsing Semntic nlysis Visitor pttern for bstrct syntx trees Some Thoughts
More informationFunctor (1A) Young Won Lim 8/2/17
Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published
More informationFunctor (1A) Young Won Lim 10/5/17
Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published
More informationSample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009
Deprtment of Computer cience Columbi University mple Midterm olutions COM W4115 Progrmming Lnguges nd Trnsltors Mondy, October 12, 2009 Closed book, no ids. ch question is worth 20 points. Question 5(c)
More informationCS 430 Spring Mike Lam, Professor. Parsing
CS 430 Spring 2015 Mike Lm, Professor Prsing Syntx Anlysis We cn now formlly descrie lnguge's syntx Using regulr expressions nd BNF grmmrs How does tht help us? Syntx Anlysis We cn now formlly descrie
More information16 Bit Software Tools ADDU-21xx-PC-1 Code Generation and Simulation
16 Bit Softwre Tools ADDU-21xx-PC-1 Code Genertion nd Simultion ADDS-21xx-PC-1 Version 6.1 Contents The entire softwre cretion tool chin in one pckge System Builder Assembler C Compiler Linker Softwre
More informationToday s Lecture. Basics of Logic Design: Boolean Algebra, Logic Gates. Recursive Example. Review: The C / C++ code. Recursive Example (Continued)
Tod s Lecture Bsics of Logic Design: Boolen Alger, Logic Gtes Alvin R. Leeck CPS 4 Lecture 8 Homework #2 Due Ferur 3 Outline Review (sseml recursion) Building the uilding locks Logic Design Truth tles,
More informationLecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure
Lecture Overview Knowledge-bsed systems in Bioinformtics, MB6 Scheme lecture Procedurl bstrction Higher order procedures Procedures s rguments Procedures s returned vlues Locl vribles Dt bstrction Compound
More informationCMSC 331 First Midterm Exam
0 00/ 1 20/ 2 05/ 3 15/ 4 15/ 5 15/ 6 20/ 7 30/ 8 30/ 150/ 331 First Midterm Exm 7 October 2003 CMC 331 First Midterm Exm Nme: mple Answers tudent ID#: You will hve seventy-five (75) minutes to complete
More informationCS201 Discussion 10 DRAWTREE + TRIES
CS201 Discussion 10 DRAWTREE + TRIES DrwTree First instinct: recursion As very generic structure, we could tckle this problem s follows: drw(): Find the root drw(root) drw(root): Write the line for the
More informationStack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures
Other Issues Stck Mnipultion support for procedures (Refer to section 3.6), stcks, frmes, recursion mnipulting strings nd pointers linkers, loders, memory lyout Interrupts, exceptions, system clls nd conventions
More informationMotivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return
Motivation Jack code (example) class class Main Main { { static static int int x; x; function function void void main() main() { { Inputs Inputs and and multiplies multiplies two two numbers numbers var
More informationCSE 401 Midterm Exam 11/5/10 Sample Solution
Question 1. egulr expressions (20 points) In the Ad Progrmming lnguge n integer constnt contins one or more digits, but it my lso contin embedded underscores. Any underscores must be preceded nd followed
More informationA Formalism for Functionality Preserving System Level Transformations
A Formlism for Functionlity Preserving System Level Trnsformtions Smr Abdi Dniel Gjski Center for Embedded Computer Systems UC Irvine Center for Embedded Computer Systems UC Irvine Irvine, CA 92697 Irvine,
More informationVirtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.
Virtual Machine Part II: Program Control Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Chapter 8:
More informationECE 468/573 Midterm 1 September 28, 2012
ECE 468/573 Midterm 1 September 28, 2012 Nme:! Purdue emil:! Plese sign the following: I ffirm tht the nswers given on this test re mine nd mine lone. I did not receive help from ny person or mteril (other
More informationMath 464 Fall 2012 Notes on Marginal and Conditional Densities October 18, 2012
Mth 464 Fll 2012 Notes on Mrginl nd Conditionl Densities klin@mth.rizon.edu October 18, 2012 Mrginl densities. Suppose you hve 3 continuous rndom vribles X, Y, nd Z, with joint density f(x,y,z. The mrginl
More informationChapter 8: Virtual Machine II: Program Control
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005 Chapter 8: Virtual Machine II: Program Control www.idc.ac.il/tecs Usage and Copyright Notice: Copyright 2005 Noam Nisan and Shimon Schocken
More informationBasics of Logic Design Arithmetic Logic Unit (ALU)
Bsics of Logic Design Arithmetic Logic Unit (ALU) CPS 4 Lecture 9 Tody s Lecture Homework #3 Assigned Due Mrch 3 Project Groups ssigned & posted to lckord. Project Specifiction is on We Due April 9 Building
More informationMIPS I/O and Interrupt
MIPS I/O nd Interrupt Review Floting point instructions re crried out on seprte chip clled coprocessor 1 You hve to move dt to/from coprocessor 1 to do most common opertions such s printing, clling functions,
More informationMidterm 2 Sample solution
Nme: Instructions Midterm 2 Smple solution CMSC 430 Introduction to Compilers Fll 2012 November 28, 2012 This exm contins 9 pges, including this one. Mke sure you hve ll the pges. Write your nme on the
More informationEngineer To Engineer Note
Engineer To Engineer Note EE-188 Technicl Notes on using Anlog Devices' DSP components nd development tools Contct our technicl support by phone: (800) ANALOG-D or e-mil: dsp.support@nlog.com Or visit
More informationData Flow on a Queue Machine. Bruno R. Preiss. Copyright (c) 1987 by Bruno R. Preiss, P.Eng. All rights reserved.
Dt Flow on Queue Mchine Bruno R. Preiss 2 Outline Genesis of dt-flow rchitectures Sttic vs. dynmic dt-flow rchitectures Pseudo-sttic dt-flow execution model Some dt-flow mchines Simple queue mchine Prioritized
More informationStack. A list whose end points are pointed by top and bottom
4. Stck Stck A list whose end points re pointed by top nd bottom Insertion nd deletion tke plce t the top (cf: Wht is the difference between Stck nd Arry?) Bottom is constnt, but top grows nd shrinks!
More informationGeometric transformations
Geometric trnsformtions Computer Grphics Some slides re bsed on Shy Shlom slides from TAU mn n n m m T A,,,,,, 2 1 2 22 12 1 21 11 Rows become columns nd columns become rows nm n n m m A,,,,,, 1 1 2 22
More informationIntroduction to Computer Science, Shimon Schocken, IDC Herzliya. Lecture Writing Classes
Introduction to Computer Science, Shimon Schocken, IDC Herzliy Lecture 5.1-5.2 Writing Clsses Writing Clsses, Shimon Schocken IDC Herzliy, www.ro2cs.com slide 1 Clsses Two viewpos on es: Client view: how
More informationDigital Design. Chapter 1: Introduction. Digital Design. Copyright 2006 Frank Vahid
Chpter : Introduction Copyright 6 Why Study?. Look under the hood of computers Solid understnding --> confidence, insight, even better progrmmer when wre of hrdwre resource issues Electronic devices becoming
More informationFrom Dependencies to Evaluation Strategies
From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute
More informationEngineer To Engineer Note
Engineer To Engineer Note EE-186 Technicl Notes on using Anlog Devices' DSP components nd development tools Contct our technicl support by phone: (800) ANALOG-D or e-mil: dsp.support@nlog.com Or visit
More informationDiscussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010
COP4600 Discussion 2 OS concepts, System cll, nd Assignment 1 TA: Hufeng Jin hj0@cise.ufl.edu Discussion 1 Recp Introduction to C C Bsic Types (chr, int, long, flot, doule, ) C Preprocessors (#include,
More informationAssembler. Building a Modern Computer From First Principles.
Assembler Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Chapter 6: Assembler slide 1 Where we are
More informationSystems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits
Systems I Logic Design I Topics Digitl logic Logic gtes Simple comintionl logic circuits Simple C sttement.. C = + ; Wht pieces of hrdwre do you think you might need? Storge - for vlues,, C Computtion
More informationToday. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search
Uninformed Serch [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.] Tody Serch Problems Uninformed Serch Methods
More informationCOMMON HALF YEARLY EXAMINATION DECEMBER 2018
li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net li.net i.net.pds.pds COMMON HALF YEARLY EXAMINATION DECEMBER 2018 STD : XI SUBJECT: COMPUTER SCIENCE
More informationComputer Arithmetic Logical, Integer Addition & Subtraction Chapter
Computer Arithmetic Logicl, Integer Addition & Sutrction Chpter 3.-3.3 3.3 EEC7 FQ 25 MIPS Integer Representtion -it signed integers,, e.g., for numeric opertions 2 s s complement: one representtion for
More informationEngineer To Engineer Note
Engineer To Engineer Note EE-167 Technicl Notes on using Anlog Devices' DSP components nd development tools Contct our technicl support by phone: (800) ANALOG-D or e-mil: dsp.support@nlog.com Or visit
More informationCSEP 573 Artificial Intelligence Winter 2016
CSEP 573 Artificil Intelligence Winter 2016 Luke Zettlemoyer Problem Spces nd Serch slides from Dn Klein, Sturt Russell, Andrew Moore, Dn Weld, Pieter Abbeel, Ali Frhdi Outline Agents tht Pln Ahed Serch
More informationCSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona
CSc 453 Compilers nd Systems Softwre 4 : Lexicl Anlysis II Deprtment of Computer Science University of Arizon collerg@gmil.com Copyright c 2009 Christin Collerg Implementing Automt NFAs nd DFAs cn e hrd-coded
More informationVirtual Machine (Part II)
Harvard University CS 101 Fall 2005, Shimon Schocken Virtual Machine (Part II) Elements of Computing Systems 1 Virtual Machine II (Ch. 8) Where we are at: Human Thought Abstract design Chapters 9, 12 H.L.
More informationIn the last lecture, we discussed how valid tokens may be specified by regular expressions.
LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.
More informationImplementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona
Implementing utomt Sc 5 ompilers nd Systems Softwre : Lexicl nlysis II Deprtment of omputer Science University of rizon collerg@gmil.com opyright c 009 hristin ollerg NFs nd DFs cn e hrd-coded using this
More informationbox Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:
Boxes nd Arrows There re two kinds of vriles in Jv: those tht store primitive vlues nd those tht store references. Primitive vlues re vlues of type long, int, short, chr, yte, oolen, doule, nd flot. References
More informationCS321 Languages and Compiler Design I. Winter 2012 Lecture 5
CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,
More informationbinary trees, expression trees
COMP 250 Lecture 21 binry trees, expression trees Oct. 27, 2017 1 Binry tree: ech node hs t most two children. 2 Mximum number of nodes in binry tree? Height h (e.g. 3) 3 Mximum number of nodes in binry
More informationCMPSC 470: Compiler Construction
CMPSC 47: Compiler Construction Plese complete the following: Midterm (Type A) Nme Instruction: Mke sure you hve ll pges including this cover nd lnk pge t the end. Answer ech question in the spce provided.
More information3.1 Data Types!!! any program you might want to write
Abstrct Dt Types 3.1 Dt Types ny progrm you might wnt to write objects functions nd modules grphics, sound, nd imge I/O rrys conditionls nd loops Mth primitive dt types text I/O ssignment sttements crete
More informationReference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays
Objects nd Clsses Reference types nd their chrcteristics Clss Definition Constructors nd Object Cretion Specil objects: Strings nd Arrys OOAD 1999/2000 Cludi Niederée, Jochim W. Schmidt Softwre Systems
More information3.1 Data Types. Abstract Data Types. Constructors and Methods. Objects
Abstrct Dt Types 3.1 Dt Types Dt type. Set of vlues nd opertions on those vlues. Abstrct dt type. Dt type whose representtion is hidden from the user. ny progrm you might wnt to write objects functions
More informationEngineer-to-Engineer Note
Engineer-to-Engineer Note EE-069 Technicl notes on using Anlog Devices DSPs, processors nd development tools Visit our Web resources http://www.nlog.com/ee-notes nd http://www.nlog.com/processors or e-mil
More informationASTs, Regex, Parsing, and Pretty Printing
ASTs, Regex, Prsing, nd Pretty Printing CS 2112 Fll 2016 1 Algeric Expressions To strt, consider integer rithmetic. Suppose we hve the following 1. The lphet we will use is the digits {0, 1, 2, 3, 4, 5,
More informationCSCI 446: Artificial Intelligence
CSCI 446: Artificil Intelligence Serch Instructor: Michele Vn Dyne [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.]
More informationScanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an
Scnner Termintion A scnner reds input chrcters nd prtitions them into tokens. Wht hppens when the end of the input file is reched? It my be useful to crete n Eof pseudo-chrcter when this occurs. In Jv,
More informationCOMP 423 lecture 11 Jan. 28, 2008
COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring
More information10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing
Motivting Exmple Lexicl nd yntx Anlysis (2) In Text: Chpter 4 Consider the grmmr -> cad A -> b Input string: w = cd How to build prse tree top-down? 2 Initilly crete tree contining single node (the strt
More informationMid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:
Fll term 2012 KAIST EE209 Progrmming Structures for EE Mid-term exm Thursdy Oct 25, 2012 Student's nme: Student ID: The exm is closed book nd notes. Red the questions crefully nd focus your nswers on wht
More informationControl-Flow Analysis and Loop Detection
! Control-Flow Anlysis nd Loop Detection!Lst time! PRE!Tody! Control-flow nlysis! Loops! Identifying loops using domintors! Reducibility! Using loop identifiction to identify induction vribles CS553 Lecture
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών
ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop
More informationWhat do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers
Wht do ll those bits men now? bits (...) Number Systems nd Arithmetic or Computers go to elementry school instruction R-formt I-formt... integer dt number text chrs... floting point signed unsigned single
More informationINTRODUCTION TO SIMPLICIAL COMPLEXES
INTRODUCTION TO SIMPLICIAL COMPLEXES CASEY KELLEHER AND ALESSANDRA PANTANO 0.1. Introduction. In this ctivity set we re going to introduce notion from Algebric Topology clled simplicil homology. The min
More informationVery sad code. Abstraction, List, & Cons. CS61A Lecture 7. Happier Code. Goals. Constructors. Constructors 6/29/2011. Selectors.
6/9/ Abstrction, List, & Cons CS6A Lecture 7-6-9 Colleen Lewis Very sd code (define (totl hnd) (if (empty? hnd) (+ (butlst (lst hnd)) (totl (butlst hnd))))) STk> (totl (h c d)) 7 STk> (totl (h ks d)) ;;;EEEK!
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 3: Lexer genertors Viktor Leijon Slides lrgely y John Nordlnder with mteril generously provided y Mrk P. Jones. 1 Recp: Hndwritten Lexers: Don t require sophisticted
More informationGeorge Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables
George Boole IT 3123 Hrdwre nd Softwre Concepts My 28 Digitl Logic The Little Mn Computer 1815 1864 British mthemticin nd philosopher Mny contriutions to mthemtics. Boolen lger: n lger over finite sets
More informationIf f(x, y) is a surface that lies above r(t), we can think about the area between the surface and the curve.
Line Integrls The ide of line integrl is very similr to tht of single integrls. If the function f(x) is bove the x-xis on the intervl [, b], then the integrl of f(x) over [, b] is the re under f over the
More informationCS 321 Programming Languages and Compilers. Bottom Up Parsing
CS 321 Progrmming nguges nd Compilers Bottom Up Prsing Bottom-up Prsing: Shift-reduce prsing Grmmr H: fi ; fi b Input: ;;b hs prse tree ; ; b 2 Dt for Shift-reduce Prser Input string: sequence of tokens
More informationMany analog implementations of CPG exist, typically using operational amplifier or
FPGA Implementtion of Centrl Pttern Genertor By Jmes J Lin Introuction: Mny nlog implementtions of CPG exist, typiclly using opertionl mplifier or trnsistor level circuits. These types of circuits hve
More informationEngineer-to-Engineer Note
Engineer-to-Engineer Note EE-204 Technicl notes on using Anlog Devices DSPs, processors nd development tools Visit our Web resources http://www.nlog.com/ee-notes nd http://www.nlog.com/processors or e-mil
More informationBefore We Begin. Introduction to Spatial Domain Filtering. Introduction to Digital Image Processing. Overview (1): Administrative Details (1):
Overview (): Before We Begin Administrtive detils Review some questions to consider Winter 2006 Imge Enhncement in the Sptil Domin: Bsics of Sptil Filtering, Smoothing Sptil Filters, Order Sttistics Filters
More informationvcloud Director Service Provider Admin Portal Guide vcloud Director 9.1
vcloud Director Service Provider Admin Portl Guide vcloud Director 9. vcloud Director Service Provider Admin Portl Guide You cn find the most up-to-dte technicl documenttion on the VMwre website t: https://docs.vmwre.com/
More informationReducing Costs with Duck Typing. Structural
Reducing Costs with Duck Typing Structurl 1 Duck Typing In computer progrmming with object-oriented progrmming lnguges, duck typing is lyer of progrmming lnguge nd design rules on top of typing. Typing
More informationLanguages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *
Pln for Tody nd Beginning Next week Interpreter nd Compiler Structure, or Softwre Architecture Overview of Progrmming Assignments The MeggyJv compiler we will e uilding. Regulr Expressions Finite Stte
More informationTopic 2: Lexing and Flexing
Topic 2: Lexing nd Flexing COS 320 Compiling Techniques Princeton University Spring 2016 Lennrt Beringer 1 2 The Compiler Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of
More informationDigital Signal Processing: A Hardware-Based Approach
Digitl Signl Processing: A Hrdwre-Bsed Approch Roert Esposito Electricl nd Computer Engineering Temple University troduction Teching Digitl Signl Processing (DSP) hs included the utilition of simultion
More informationData sharing in OpenMP
Dt shring in OpenMP Polo Burgio polo.burgio@unimore.it Outline Expressing prllelism Understnding prllel threds Memory Dt mngement Dt cluses Synchroniztion Brriers, locks, criticl sections Work prtitioning
More informationZenoss Core Installation Guide
Zenoss Core Instlltion Guide Relese 5.2.1 Zenoss, Inc. www.zenoss.com Zenoss Core Instlltion Guide Copyright 2017 Zenoss, Inc. All rights reserved. Zenoss nd the Zenoss logo re trdemrks or registered trdemrks
More informationCoprocessor memory definition. Loic Pallardy / Arnaud Pouliquen
Coprocessor memory definition Loic Pllrdy / Arnud Pouliquen Objective 2 The gol of following slides is to sum up on-going discussion in OpenAP weekly bout Remoteproc/Rpmsg memory lloction. Following proposl
More informationCOMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples
COMPUTER SCIENCE 123 Foundtions of Computer Science 6. Tuples Summry: This lecture introduces tuples in Hskell. Reference: Thompson Sections 5.1 2 R.L. While, 2000 3 Tuples Most dt comes with structure
More informationcisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:
cisc1110 fll 2010 lecture VI.2 cll y vlue function prmeters more on functions more on cll y vlue nd cll y reference pssing strings to functions returning strings from functions vrile scope glol vriles
More informationMath 142, Exam 1 Information.
Mth 14, Exm 1 Informtion. 9/14/10, LC 41, 9:30-10:45. Exm 1 will be bsed on: Sections 7.1-7.5. The corresponding ssigned homework problems (see http://www.mth.sc.edu/ boyln/sccourses/14f10/14.html) At
More informationOn components with explicit protocols satisfying a notion of correctness by construction
On components with explicit protocols stisfying notion of correctness by construction Andrés Frís nd Mrio Südholt Déprtement Informtique École des Mines de Nntes 4, rue Alfred Kstler BP 20722 F-44307 Nntes
More informationScope, Functions, and Storage Management
Scope, Functions, nd Storge Mngement Block-structured lnguges nd stck storge In-le Blocks (previous set of overheds) ctivtion records storge for locl, glol vriles First-order functions (previous set of
More informationLists in Lisp and Scheme
Lists in Lisp nd Scheme Lists in Lisp nd Scheme Lists re Lisp s fundmentl dt structures, ut there re others Arrys, chrcters, strings, etc. Common Lisp hs moved on from eing merely LISt Processor However,
More informationLING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong
LING/C SC/PSYC 438/538 Lecture 21 Sndiwy Fong Tody's Topics Homework 8 Review Optionl Homework 9 (mke up on Homework 7) Homework 8 Review Question1: write Prolog regulr grmmr for the following lnguge:
More information5 Regular 4-Sided Composition
Xilinx-Lv User Guide 5 Regulr 4-Sided Composition This tutoril shows how regulr circuits with 4-sided elements cn be described in Lv. The type of regulr circuits tht re discussed in this tutoril re those
More informationWhat do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers
Wht do ll those bits men now? bits (...) Number Systems nd Arithmetic or Computers go to elementry school instruction R-formt I-formt... integer dt number text chrs... floting point signed unsigned single
More informationRegister Transfer Level (RTL) Design
CSE4: Components nd Design Techniques for Digitl Systems Register Trnsfer Level (RTL) Design Tjn Simunic Rosing Where we re now Wht we hve covered lst time: Register Trnsfer Level (RTL) design Wht we re
More informationMATH 25 CLASS 5 NOTES, SEP
MATH 25 CLASS 5 NOTES, SEP 30 2011 Contents 1. A brief diversion: reltively prime numbers 1 2. Lest common multiples 3 3. Finding ll solutions to x + by = c 4 Quick links to definitions/theorems Euclid
More informationEnginner To Engineer Note
Technicl Notes on using Anlog Devices DSP components nd development tools from the DSP Division Phone: (800) ANALOG-D, FAX: (781) 461-3010, EMAIL: dsp_pplictions@nlog.com, FTP: ftp.nlog.com Using n ADSP-2181
More information! Smaller, simpler, subcomponent of program! Provides abstraction. n hide low-level details, give high-level structure
Function Chpte 1 Functions Oiginl slides fom Gegoy Byd, Noth Colin Stte Univesity Modified slides by Chis Wilcox, Colodo Stte Univesity! Smlle, simple, subcomponent of pogm! Povides bstction n hide lo-level
More informationProblem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.
Problem Set 2 Fll 16 Due: Wednesdy, September 21th, in clss, before clss begins. 1. LL Prsing For the following sub-problems, consider the following context-free grmmr: S T$ (1) T A (2) T bbb (3) A T (4)
More informationIntroduction To Files In Pascal
Why other With Files? Introduction To Files In Pscl Too much informtion to input ll t once The informtion must be persistent (RAM is voltile) Etc. In this section of notes you will lern how to red from
More informationQuestions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers?
Questions About Numbers Number Systems nd Arithmetic or Computers go to elementry school How do you represent negtive numbers? frctions? relly lrge numbers? relly smll numbers? How do you do rithmetic?
More informationMemory Management Functions
Meory Mngeent Functions Chpter 9 Meory Mngeent Process of binding vlues to eory loctions Vlues y be sttic or dynic Vlues re ssigned t different plces Sttic eory Run-tie stck Hep 1 Meory Mngeent Sttic Meory
More informationStained Glass Design. Teaching Goals:
Stined Glss Design Time required 45-90 minutes Teching Gols: 1. Students pply grphic methods to design vrious shpes on the plne.. Students pply geometric trnsformtions of grphs of functions in order to
More informationQuiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex
Long Quiz2 45mins Nme: Personl Numer: Prolem. (20pts) Here is n Tle of Perl Regulr Ex Chrcter Description. single chrcter \s whitespce chrcter (spce, t, newline) \S non-whitespce chrcter \d digit (0-9)
More information