CSE 3302 Notes 5: Memory Management
|
|
- Arnold Mills
- 5 years ago
- Views:
Transcription
1 CSE 0 Notes 5: Memory Management (Last updated 10/7/15 1:6 PM) References: Gabbrielli-Martini: 5 Wirth: IMPLEMENTING SIMPLE SUBPROGRAMS Historical FORTRAN and COBOL Simple = no recursion static allocation minimal call-by-value call-by-reference for anything non-trivial If program starts, it will have enough memory Gabbrielli, figure one activation record per subprogram Layout of activation record (a.r., stack frame), register conventions mandated by vendor Who saves registers? - caller or callee? 5.. IMPLEMENTING SUBPROGRAMS WITH RUN-TIME STACK PL/0 Calling Sequence: Caller cal l,a: call procedure a (absolute address) at level l cal: begin {generate new block mark} s[t + 1] := base(l); { static link for nested procs } s[t + ] := b; { dynamic link to caller proc } s[t + ] := p; { return address } b := t + 1; { new base of stack frame p := a { new program counter } Dynamic link is needed for C; Pascal and PL/0 also need static (i.e. lexical scope) link for immediate containing procedure.
2 Called Pascal-S jmp over any instructions for any nested procedures int 0,a : increment t-register by a { a includes slots for cal } Return Sequence Called int: t := t + a; { allocate stack frame including sl, dl, ra } opr 0,a : execute operation a (=0 here) Caller does nothing special opr: case a of {operator} 0: begin {return} t := b - 1; { discard stack frame } p := s[t + ]; { return to caller } b := s[t + ]; { old base address } Interpreter addressing is done using display array to avoid cost of base function. 5.. REFERENCING STACK-DYNAMIC LOCAL VARIABLES FOR NESTED SUBPROGRAMS A nested subprogram may potentially reference local variables for subprograms that contain it. Two difficulties (that also interact): 1. Calls among nested subprograms at same level.. Recursion For a given variable (under lexical/static scoping), the most recent invocation of each containing subprogram is the one whose activation record is needed. (The outermost scope is level 0. Nested scopes have increasing level numbers.) There is exactly one activation record per level in the (ascending) static chain. PL/0 Assumption - non-local data is rarely accessed, simple solution is sufficient Referencing is based on: Compiler computes level difference to put into lod, sto, and cal instructions cal instruction sets saved static link (s[t + 1]) to point at next level a.r.
3 Level difference is used with loop to follow static links: instruction = packed record f: fct; {function code} l: 0..levmax; {level} a: {0..amax} integer {displacement address} function base(l: integer): integer; var b1: integer; begin b1 := b; {find base l levels down} while l > 0 do begin b1 := s[b1]; l := l - 1 base := b1 end {base}; To help with optimizing code, compilers may use a sequence of indirections. 0 var a; 1 1 procedure b; 1 1 var c,d; procedure e; var f,g,h; begin 4 a:=1; 6 c:=; 8 d:=; 10 f:=4; 1 g:=5; 14 h:=6; 16 call e; 17 call b begin 0 a:=7; c:=8; 4 call e; 5 call b begin 8 a:=9; 0 if 0=1 then call b 5 end. start pl/0 end pl/0 0 jmp 0 7 These jmp s get compiled in block with gen(jmp,0,0), but are patched 1 jmp 0 19 when the start addresses are known. (Just before statement is called in block.) jmp 0 int 0 6 code for e 4 lit sto 5 a 6 lit 0 7 sto 1 c 8 lit 0 9 sto 1 4 d 10 lit sto 0 f 1 lit sto 0 4 g 14 lit sto 0 5 h 16 cal 1 e 17 cal 1 b 18 opr 0 0 return 19 int 0 5 code for b 0 lit sto 1 5 a lit 0 8 sto 0 c 4 cal 0 e 5 cal 1 19 b 6 opr 0 0 return 7 int 0 6 code for unnamed driver 8 lit sto 0 5 a 0 lit lit 0 1 opr 0 8 = jpc cal 0 19 b 5 opr 0 0 return
4 0 var aout,result; b=1 p=9 initial result 1 procedure a(ain); var bout; 0 ret adr procedure b(bin); 0 d.l. var cout; b=8 p=9 after call to a 1 0 bout procedure c(cin); 11 1 ain ret adr 4 begin 9 1 d.l. 5 cout:=cin+8; 8 1 s.l. 9 result:=ain+bin+cin result 15 4 int 0 4 code for c 5 lod 0 cin 6 lit ret adr 7 opr d.l. 8 sto 1 4 cout 9 lod ain b=1 p=19 after call to b 10 lod 1 bin 17 0 cout 11 opr bin 1 lod 0 cin 15 ret adr 1 opr d.l. 14 lit s.l. 15 opr bout 16 sto 6 result 11 1 ain 17 opr 0 0 return 10 4 ret adr 18 begin 9 1 d.l. 19 call c(4); 8 1 s.l. bout:=bin+cout 7 0 result 5 18 int 0 5 code for b 19 int 0 push args(s) for c 0 lit ret adr 1 int 0-4 -(+number of args) 0 d.l. cal 0 4 c lod 0 bin b=18 p=5 after call to c 4 lod 0 4 cout 1 4 cin 5 opr ret adr 6 sto 1 4 bout 19 1 d.l. 7 opr 0 0 return 18 1 s.l cout 8 begin 16 bin 9 call b(); 15 ret adr aout:=ain+bout 14 8 d.l s.l. 8 int 0 5 code for a 1 0 bout 9 int 0 push args(s) for b 11 1 ain 0 lit ret adr 1 int 0-4 -(+number of args) 9 1 d.l. cal 0 18 b 8 1 s.l. lod 0 ain 7 0 result 4 lod 0 4 bout 5 opr sto 1 5 aout 7 opr 0 0 return 0 ret adr 8 0 d.l. 8 begin 9 call a(1); 4 out:=aout; 45 out:=result 46 end. start pl/ end pl 8 int 0 7 code for unnamed driver 9 int 0 push args(s) for a 40 lit int 0-4 -(+number of args) 4 cal 0 8 a 4 lod 0 5 aout 44 wro lod 0 6 result 46 wro opr 0 0 return 4
5 0 procedure iloop(i); 41 int 0 4 lit 0 0 procedure jloop(j); 4 int cal 0 4 kloop procedure kloop(k); 45 lod 0 j 4 46 lit begin 47 opr 0 8 = 5 k:=k+1; 48 jpc out:=i+j+k; 49 int 0 15 if k< then 50 lod 1 i 18 call kloop(k); 51 int 0-4 if k= then 5 cal 1 iloop 6 call jloop(j) 5 opr 0 0 return int 0 4 kloop code 54 begin 5 lod 0 k 55 i:=i+100; 6 lit if i<00 then 7 opr call jloop(0) 8 sto 0 k 67 9 lod i 54 int 0 4 iloop code 10 lod 1 j 55 lod 0 i 11 opr lit lod 0 k 57 opr opr sto 0 i 14 wro lod 0 i 15 lod 0 k 60 lit lit 0 61 opr 0 10 < 17 opr 0 10 < 6 jpc jpc 0 6 int 0 19 int 0 64 lit lod 0 k 65 int int cal 0 jloop cal 1 4 kloop 67 opr 0 0 return lod 0 k 68 4 lit 0 68 begin 5 opr 0 8 = 69 call iloop(0) 6 jpc end. 7 int 0 68 int lod 1 j 69 int 0 9 int lit cal jloop 71 int opr 0 0 return 7 cal 0 54 iloop 7 opr 0 0 return begin b=6 p=15 (after out:=i+j+k;) j:=j+10; 65 k ******** 7 if j<0 then 64 ret adr 40 call kloop(0); 6 58 d.l. 45 if j=0 then 6 54 s.l. 48 call iloop(i) 61 1 k ret adr int 0 4 jloop code d.l. lod 0 j s.l. 4 lit j ******** 5 opr ret adr 6 sto 0 j d.l. 7 lod 0 j 54 8 s.l. 8 lit k 9 opr 0 10 < 5 ret adr 40 jpc d.l s.l k ret adr 47 4 d.l s.l j ret adr 4 8 d.l. 4 8 s.l i ******** 40 5 ret adr 9 4 d.l. 8 1 s.l. 7 0 j 6 1 ret adr 5 0 d.l. 4 6 s.l. k ret adr 1 6 d.l. 0 s.l. 9 1 k 8 45 ret adr 7 d.l. 6 s.l. 5 0 j 4 1 ret adr 18 d.l. 6 s.l. 1 k 0 ret adr d.l s.l k ret adr d.l s.l j 1 67 ret adr 11 6 d.l s.l i 8 7 ret adr 7 1 d.l. 6 1 s.l. 0 ret adr 0 d.l. start pl/ Heap(-Dynamic) Allocation Most flexible temporally (Historical) Pascal implementation - same space as stack, Buddy systems - maintain available blocks of size k for various k (aside - use Fibonacci sequence with arbitrary starting pair to approach ratio)
6 One or many free lists? 6 Many - Start with list of closest adequate size, continuing through lists for larger sizes until non-empty list is found Fragmentation One - ordered or unordered by size?, first fit or best fit? External - unallocated space between allocated blocks Internal - extra space inside allocated block Compaction is a possible when pointer flexibility is restricted for purposes of garbage collection Implementing Display as Alternative to Traversing Static Chain Concepts: Gabbrielli Makes no assumption regarding locality of references Instructions include absolute level and offset No static chain traversals... since number of scope levels is small, each access references the display. Trivial implementations use expensive approach of rebuilding the entire display for each call (just use the base loop). (Caches on modern machines lessen the performance advantage of displays) Every call saves and modifies one slot of the display. Every return restores one slot of the display. pl0.display..js at has details - see base, cal and return processing for differences Pascal-S aside (section 4 of report) Every call saves and modifies one slot of the display. Returns on callee side do not restore any display slots. A nested caller for an outer procedure will restore as many display slots as levels - after return
low and not larger than high. 18 points
CSE 330 Test 1 (1 point) Spring 015 Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Lisp was invented at: A. IBM B. MIT C. Netscape D. Stanford. In C++, what operator is
More informationSystem Software Assignment 1 Runtime Support for Procedures
System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such
More informationSeparate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention
Runtime Environment The Procedure Abstraction and Separate Compilation Topics we will cover The procedure abstraction and linkage conventions Runtime storage convention Non-local data access (brief) These
More informationRun-time Environments - 2
Run-time Environments - 2 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Conceptual Structure of
More informationSpecial Topics: Programming Languages
Lecture #17 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 17 Lecture #17 1 Slide 1 Runtime Representations Variable Names Environment L-values Scope, Extent
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Outline of Lecture 15 Generation
More informationImplementing Subprograms
Implementing Subprograms In Text: Chapter 10 Slide 1 Implementing Subprograms Call - Save registers - provide storage for parameters - provide storage for locals - save execution status of caller - provide
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationImplementing Subprograms
1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return
More informationProgramming Languages: Lecture 12
1 Programming Languages: Lecture 12 Chapter 10: Implementing Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 10 Topics 2 The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing
More informationChapter 10. Implementing Subprograms ISBN
Chapter 10 Implementing Subprograms ISBN 0-321-33025-0 Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables
More information! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?
A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function
More informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is
More informationRun-time Environment
Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationConcepts Introduced in Chapter 7
Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation
More informationRun Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction
Procedure Abstraction Run Time Environment Records Procedure Linkage Name Translation and Variable Access Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at
More informationRun Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access
Run Time Environment Activation Records Procedure Linkage Name Translation and Variable Access Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University
More informationTopic 7: Activation Records
Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object
More informationProcedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End
COMP 412 FALL 2017 Procedure and Function Calls, Part II Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students
More informationThe basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table
SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating
More informationFunction Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)
Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register
More informationToday's Topics. CISC 458 Winter J.R. Cordy
Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing
More informationExample. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :
Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the
More informationCompilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1
Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for
More informationProcedure and Object- Oriented Abstraction
Procedure and Object- Oriented Abstraction Scope and storage management cs5363 1 Procedure abstractions Procedures are fundamental programming abstractions They are used to support dynamically nested blocks
More informationChapter 9. Def: The subprogram call and return operations of a language are together called its subprogram linkage
Def: The subprogram call and return operations of a language are together called its subprogram linkage Implementing FORTRAN 77 Subprograms Call Semantics: 1. Save the execution status of the caller 2.
More informationCIT Week13 Lecture
CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationPrinciples of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004
Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?
More informationLecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1
Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces
More informationCSE 3302 Notes 7: Control Abstraction
CSE 3302 Notes 7: Control Abstraction (Last updated 11/1/15 12:35 PM) References: Gabbrielli-Martini: 7; Dybvig: 5.5, 5.7 7.1. SUBPROGRAMS Interfacing Concepts: Parameters: Mathematics: Parameters Arguments
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent instructions and conventions 2 Function Call Problems (1) Calling and returning
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes
More informationCS 480 Fall Runtime Environments. Mike Lam, Professor. (a.k.a. procedure calls and heap management)
CS 480 Fall 2015 Mike Lam, Professor Runtime Environments (a.k.a. procedure calls and heap management) Subprograms General characteristics Single entry point Caller is suspended while subprogram is executing
More informationChapter 10 Implementing Subprograms
Chapter 10 Implementing Subprograms The General Semantics of Calls and Returns - Definition: The subprogram call and return operations of a language are together called its subprogram linkage Implementing
More informationCSE 504: Compiler Design. Runtime Environments
Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices
More informationCSC 2400: Computing Systems. X86 Assembly: Function Calls"
CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More informationCSC 8400: Computer Systems. Using the Stack for Function Calls
CSC 84: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationG53CMP: Lecture 14. Run-Time Organisation I. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 14 p.1/37
G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 14 p.1/37 This Lecture One aspect of run-time organisation: stack-based storage allocation Lifetime
More informationCSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:
Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Seminar Analysis and Verification of Pointer Programs (WS
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"
More informationImplementing Subprograms
Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing
More informationThis Lecture. G53CMP: Lecture 14 Run-Time Organisation I. Example: Lifetime (1) Storage Areas
This Lecture G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK One aspect of run-time organisation: stack-based storage allocation Lifetime and storage Basic stack
More informationTypical Runtime Layout. Tiger Runtime Environments. Example: Nested Functions. Activation Trees. code. Memory Layout
Tiger Runtime Environments Compile-time environments are just symbol tables; they are used to assist static semantic analysis, code generation and code optimization. Run-time environments are about how
More informationBinding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill
Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s
More informationFunctions in MIPS. Functions in MIPS 1
Functions in MIPS We ll talk about the 3 steps in handling function calls: 1. The program s flow of control must be changed. 2. Arguments and return values are passed back and forth. 3. Local variables
More informationRun-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13
Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,
More informationScope, Functions, and Storage Management
Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Seminar Analysis and Verification of Pointer Programs (WS
More informationAssembly Language: Function Calls. Goals of this Lecture. Function Call Problems
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"
More informationCSC 2400: Computing Systems. X86 Assembly: Function Calls
CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls
Princeton University Computer Science 217: Introduction to Programming Systems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent
More informationImplementing Subroutines. Outline [1]
Implementing Subroutines In Text: Chapter 9 Outline [1] General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested
More informationStorage in Programs. largest. address. address
Storage in rograms Almost all operand storage used by programs is provided by memory. Even though registers are more efficiently accessed by instructions, there are too few registers to hold the stored
More informationDesign Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8
Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns
More informationProcedure-Calling Conventions October 30
Procedure-Calling Conventions October 30 CSC201 Section 002 Fall, 2000 Saving registers Registers are inevitably used by subroutines; changes their! Registers have global scope; calling procedures also
More informationCSC 2400: Computer Systems. Using the Stack for Function Calls
CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationRuntime Environments I. Basilio B. Fraguela
Runtime Environments I Basilio B. Fraguela Runtime System Responsibilities Allocation of storage for program data Sometimes also deallocation Garbage collection Management of data structures the compiled
More informationSystems I. Machine-Level Programming V: Procedures
Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp
More informationLecture 9: Procedures & Functions. CS 540 George Mason University
Lecture 9: Procedures & Functions CS 540 George Mason University Procedures/Functions Control Abstraction call/return semantics, parameters, recursion Controlled Namespace Scope (local/non-local), binding,
More informationMemory Management and Run-Time Systems
TDDD55 Compilers and Interpreters TDDB44 Compiler Construction Memory Management and Run-Time Systems Part of the Attribute Grammar Material Presented at the Beginning of this Lecture Peter Fritzson IDA,
More information12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return
Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested
More informationSymbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.
Symbol Tables ASU Textbook Chapter 7.6, 6.5 and 6.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Definitions Symbol table: A data structure used by a compiler to keep track
More informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationThe Procedure Abstraction
The Procedure Abstraction Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures
More informationTHEORY OF COMPILATION
Lecture 10 Activation Records THEORY OF COMPILATION EranYahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec10.pptx Reference: Dragon 7.1,7.2. MCD 6.3,6.4.2 1 You are here Compiler txt Source Lexical
More informationThe Stack & Procedures
The Stack & Procedures CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 2 due
More informationG Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing
More informationCourse Administration
Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701
More informationCS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11
CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table
More informationRun Time Environments
Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source
More informationCSc 520 Principles of Programming Languages. Questions. rocedures as Control Abstractions... 30: Procedures Introduction
Procedures as Control Abstractions CSc 520 Principles of Programming Languages 30: Procedures Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona
More informationAttributes of Variable. Lecture 13: Run-Time Storage Management. Lifetime. Value & Location
Attributes of Variable Lecture 13 Run-Time Storage Management CSC 131 Kim Bruce Scope Lifetime Location Value Done! Lifetime Value & Location FORTRAN - all allocated statically - Stack-based (C/C++/Java/Pascal/...)
More informationLecture 7: Binding Time and Storage
Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The
More informationScope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule
Scope CSC 4181 Compiler Construction Scope and Symbol Table A scope is a textual region of the program in which a (name-to-object) binding is active. There are two types of scope: Static scope Dynamic
More informationCSC 2400: Computer Systems. Using the Stack for Function Calls
CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationChapter 10. Implementing Subprograms
Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms
More informationSubprograms, Subroutines, and Functions
Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the
More informationRuntime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V.
Runtime management CS3300 - Compiler Design Runtime management V Krishna Nandivada IIT Madras Copyright c 2001 by Antony L Hosking Permission to make digital or hard copies of part or all of this work
More informationChapter 3:: Names, Scopes, and Bindings
Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation
More informationLecture 5. Announcements: Today: Finish up functions in MIPS
Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In
More informationCompiler Construction
Compiler Construction Lecture 15: Code Generation I (Intermediate Code) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/
More informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationCompiler Construction
Compiler Construction Lecture 15: Code Generation I (Intermediate Code) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/
More informationFunctions and Procedures
Functions and Procedures Function or Procedure A separate piece of code Possibly separately compiled Located at some address in the memory used for code, away from main and other functions (main is itself
More informationLectures Basics in Procedural Programming: Machinery
Lectures 3-4-5-6 Basics in Procedural Programming: Machinery February 21-28, 2014 2014-03-01 11:04:07 1/48 Lecture3-6E-2014.pdf (#21) Basics in Procedural Programming: Machinery Naming and Binding Mutable
More informationCS 314 Principles of Programming Languages. Lecture 13
CS 314 Principles of Programming Languages Lecture 13 Zheng Zhang Department of Computer Science Rutgers University Wednesday 19 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationToday. Putting it all together
Today! One complete example To put together the snippets of assembly code we have seen! Functions in MIPS Slides adapted from Josep Torrellas, Craig Zilles, and Howard Huang Putting it all together! Count
More informationProgramming Languages Third Edition. Chapter 10 Control II Procedures and Environments
Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing
More informationCompilers and Code Optimization EDOARDO FUSELLA
Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of
More informationAnnouncements. Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly. Agenda. SRC Procedure Calls. SRC Memory Layout. High Level Program
Fall 2006 CS333: Computer Architecture University of Virginia Computer Science Michele Co Announcements Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly Homework #2 Due next Wednesday, Sept.
More informationIntermediate Code Generation
Intermediate Code Generation Front-end intermediate code generation source program Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator intermediate representation Symbol Table Advantages
More information