# System Software Assignment 1 Runtime Support for Procedures

Size: px
Start display at page:

Transcription

2 MODULE Test; (* level 0 *) PROCEDURE S(); (* level 1 *) VAR a: INTEGER; PROCEDURE E(); (* level 2 *) (* the stack coming from *) (* S, Q, Q, P is depicted *) (* on the right *) END E; PROCEDURE Q(); (* level 2 *) VAR k: INTEGER; PROCEDURE P(); (* level 3 *) VAR j: INTEGER; E() END P; S a: INTEGER E Q k: INTEGER P j: INTEGER IF b THEN Q() ELSE P() END END Q; Q() END S; END Test. Figure 2: Nested procedures example. 2

3 E P Q Q S dynamic link static link Figure 3: Stack layout. Table 1: Local variables access examples Calling convention Access convention one level deeper: S Q S: a := 42; push FP mov a[fp], 42 call Q same level: E Q E: a := 42; push 8[FP] mov R0, 8[FP] call Q mov a[r0], 42 one level higher: P Q P: a := 42; mov R0, 8[FP] mov R0, 8[FP] push 8[R0] mov R1, 8[R0] call Q mov a[r1], 42 3

4 MODULE Test; VAR x: PROCEDURE(); PROCEDURE P(); PROCEDURE Q(); END Q; x := Q (* this is an illegal statement *) END P; P(); (* now x points to an invalid location! *) END Figure 4: Function pointer example. 4

5 Exercise 2: C calling conventions The C language supports open parameter lists (e.g., void foo(int a, int b,...);), in other words: the number of arguments is not fix and can be larger than the specified parameters (in our example two or more). 1. Which is the formula to compute the address of the parameters on the stack? Let s look at an example using the printf function (in C) which has an open list of parameters. printf("%i %i %i %i", p0, p1, p2, p3); If we pass the parameters p i left to right (like in Java or Oberon) the address of a parameter will be (Figure 5 shows the stack layout): addr(p i ) := F P + padding + size(p n ) + size(p n 1 ) size(p i+1 ) FP RET pn... p1 p0 Figure 5: Left to right parameter passing. To compute the address of a parameter we need the total number (n) of actual parameters which is unknown at compile time. If we pass the parameters right to left (like in C) the address of a parameter will be (Figure 6 shows the stack layout): addr(p i ) := F P + padding + size(p 0 ) + size(p 1 ) size(p i 1 ) posing no problem at compile time! FP RET p0 p1 p2... Figure 6: Right to left parameter passing. 2. Give the implementation of the actions call and return in pseudocode. 5

6 The only problem that is generated by the presence of a variable number of parameters is the size of procedure frame is not known at compile time. When a procedure returns, the parameters must be removed from the stack but their is unknown. To avoid this problem the old stack pointer is stored on the stack (as a last hidden parameter) and later used to restore the stack after the called procedure has returned. This is the implementation of call and return with a variable number of parameters (the problem s specific code is highlighted in bold) The only change in the implementation is of course the order of the parameters and the additional storage of the stack pointer. Call Return save registers push parameters (right to left) push SP save PC branch save FP FP := SP allocate locals Remove Locals restore FP restore PC restore the SP (remove parameters) restore registers 6

7 Exercise 3: Parameter passing 1. Why do compilers typically allocate space for arguments in the stack, even when they pass them in registers? In this way when a parameter has to be written to memory (if and additional register is needed) it can be written in the stack as all the other parameters without having to handle it in a special way. Let s look at an example: on the PowerPC architecture registers 3 to 10 can be used to pass arguments. void foo(int a, int b, int c) { while (a > 0) foo(a-1, b, c); } At the first call of foo the three parameters will be stored to R3-R5. When foo calls itself recursively the registers R3 to R5 are again needed to store the parameters. The old values of R3,R4 and R5 have to be written back to memory. In this case the three registers can safely be written on the stack as any other parameter. 2. How can complex variables (arrays and records) be passed to a procedure. Discuss two possibilities and comment their efficiency A first simple possibility is to copy these structures on the stack. This approach has two major drawbacks: a lot of time is required to copy all the data at every procedure invocation, and huge stack frames are generated (as an example the size of an ARRAY 1024,1024 OF LONGREAL is 8MB). Some languages only allow this type of variables to be passed by reference eliminating the problem. Some other language allow to pass records and arrays by reference read-only: in this way the structures can be passed by reference avoiding the copy. When the callee wants to write on these structures the data is copied to another location (lazy copy) 3. Which is the problem when passing a constant by reference? How could this problem be avoided? If a constant is passed by reference, the callee could modify it since the address of the memory location is passed on the stack and the called procedure cannot be aware of the fact the actual parameter is, in fact, a constant. To avoid the problem a constant should be copied to a temporary location and the address of this temporary location should be passed to the callee. 7

8 Exercise 4: Return values Functions can return a value to the caller (e.g., PROCEDURE foo(): INTEGER; in Oberon or int foo(); in C). In Oberon it is only possible to return a scalar value or a pointer, other languages like C allow more complex structures to be returned. 1. Describe a simple way to return a value from the callee to the caller in Oberon (scalars and pointers only). When only scalars and pointers can be returned the maximum size of the returned variable is known and fix (normally four or eight bytes). In this case one or two registers can be reserved to this scope (on PowerPC usually R3, on Intel EAX). 2. Explain what should be done to return complex structures like records and arrays. This can be solved in two ways: either the caller gives the address of the structure that will be used by return to the callee (this corresponds to an hidden parameter), or the callee returns a pointer to a static variable where the structure is stored. 8

### CA 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

### Design 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

### Run-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

### Run-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

### Run-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

### G 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

### Wednesday, October 15, 14. Functions

Functions Terms void foo() { int a, b;... bar(a, b); void bar(int x, int y) {... foo is the caller bar is the callee a, b are the actual parameters to bar x, y are the formal parameters of bar Shorthand:

### Procedure 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

### CSC 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

### Compiler Design. Spring Run-Time Environments. Sample Exercises and Solutions. Prof. Pedro C. Diniz

University of Southern California (USC) Computer Science Department Compiler Design Spring 2014 Run-Time Environments Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute

### CIT 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

### Run-Time Environments

1 Run-Time Environments Chapter 7 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011 2 Procedure Activation and Lifetime A procedure is activated when called

### Systems 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

### CSC 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

### CSE 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

### What 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

### Implementing 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

### THEORY 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

### Topic 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

### 143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017

143A: Principles of Operating Systems Lecture 4: Calling conventions Anton Burtsev October, 2017 Recap from last time Stack and procedure calls What is stack? Stack It's just a region of memory Pointed

### Implementing 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

### Chapter 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

### Lecture08: Scope and Lexical Address

Lecture08: Scope and Lexical Address Free and Bound Variables (EOPL 1.3.1) Given an expression E, does a particular variable reference x appear free or bound in that expression? Definition: A variable

### Principles of Programming Languages

Ting Zhang Iowa State University Computer Science Department Lecture Note 16 October 26, 2010 Control Abstraction: Subroutines 1 / 26 Outline 1 Subroutines 2 Parameter Passing 3 Generic Subroutines 2 /

### Run-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

### Compilation /15a Lecture 7. Activation Records Noam Rinetzky

Compilation 0368-3133 2014/15a Lecture 7 Activation Records Noam Rinetzky 1 Code generation for procedure calls (+ a few words on the runtime system) 2 Code generation for procedure calls Compile time

### 143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017

143A: Principles of Operating Systems Lecture 5: Calling conventions Anton Burtsev January, 2017 Stack and procedure calls Stack Main purpose: Store the return address for the current procedure Caller

### CSC 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

### ! 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

### Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

Call without Parameter Value Transfer What are involved? ESP Stack Pointer Register Grows by 4 for EIP (return address) storage Stack -- Memory which holds register contents Will keep the EIP of the next

### ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

### Implementing 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

### Assembly III: Procedures. Jo, Heeseung

Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

### CSC 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

### G 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

### CS 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:

### Programming 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

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

### Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

### Separate 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

### Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12 Goals for Today Calling Convention for Procedure Calls Enable code to be reused by allowing

### Functions 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

### We can emit stack-machine-style code for expressions via recursion

Code Generation The Main Idea of Today s Lecture We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

### 12/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

### Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

ECE 2035(B) Programming for Hardware/Software Systems Fall 2013 Exam Two October 22 nd 2013 Name: Q1: /20 Q2: /30 Q3: /24 Q4: /26 Total: /100 1/6 For functional call related questions, let s assume the

### CSc 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

### Function 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

### 238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

238P: Operating Systems Lecture 3: Calling conventions Anton Burtsev October, 2018 What does CPU do internally? (Remember Lecture 01 - Introduction?) CPU execution loop CPU repeatedly reads instructions

### Run 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

### G53CMP: 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

### Run-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,

### This 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

### CSC 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

### CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

CS356: Discussion #6 Assembly Procedures and Arrays Marco Paolieri (paolieri@usc.edu) Procedures Functions are a key abstraction in software They break down a problem into subproblems. Reusable functionality:

### Procedure Call. Procedure Call CS 217. Involves following actions

Procedure Call CS 217 Procedure Call Involves following actions pass arguments save a return address transfer control to callee transfer control back to caller return results int add(int a, int b) { return

### Run 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

### CSE 3302 Notes 5: Memory Management

CSE 0 Notes 5: Memory Management (Last updated 10/7/15 1:6 PM) References: Gabbrielli-Martini: 5 Wirth: 4 5.1. IMPLEMENTING SIMPLE SUBPROGRAMS Historical FORTRAN and COBOL Simple = no recursion static

### Today'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

### Compilers 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

### Procedure-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

### CSCI Compiler Design

CSCI 565 - Compiler Design Spring 2010 Final Exam - Solution May 07, 2010 at 1.30 PM in Room RTH 115 Duration: 2h 30 min. Please label all pages you turn in with your name and student number. Name: Number:

### Code Generation & Parameter Passing

Code Generation & Parameter Passing Lecture Outline 1. Allocating temporaries in the activation record Let s optimize our code generator a bit 2. A deeper look into calling sequences Caller/Callee responsibilities

### CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

### Lecture #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

### ! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Problem Chapter 10 Memory Model for Program Execution Original slides by Chris Wilcox, Colorado State University How do we allocate memory during the execution of a program written in C?! Programs need

### CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 CS429 Slideset 9: 1 Mechanisms in Procedures

### Example. 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

### CSCI565 Compiler Design

CSCI565 Compiler Design Spring 2011 Homework 4 Solution Due Date: April 6, 2011 in class Problem 1: Activation Records and Stack Layout [50 points] Consider the following C source program shown below.

### CS213. Machine-Level Programming III: Procedures

CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward

### Topic 3-a. Calling Convention 2/29/2008 1

Topic 3-a Calling Convention 2/29/2008 1 Calling Convention Calling convention is a standardized method for a program to pass parameters to a procedure and receive result values back from it. 2/29/2008

### Chapter 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.

### Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline

### CS558 Programming Languages

CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

### Memory 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,

### Machine Programming 3: Procedures

Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure

### MIPS Functions and the Runtime Stack

MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

### Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 27 : Control Structures Procedures Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

### Concepts 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

### Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5 6 compute jump/branch targets memory PC +4 new pc Instruction Fetch

### The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt

### COL728 Minor2 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20

COL728 Minor2 Exam Compiler Design Sem II, 2017-18 Answer all 5 questions Max. Marks: 20 1. Short questions a. Give an example of a program that is not a legal program if we assume static scoping, but

### 1 Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

### Module 27 Switch-case statements and Run-time storage management

Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

### Run-time Environments - 3

Run-time Environments - 3 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

### Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure

### Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Stack Frames Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 15 Outline Preserving Registers Saving and Restoring Registers

### Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure

### ECE260: Fundamentals of Computer Engineering

Supporting Nested Procedures James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy Memory Layout

### Chapter 10 Memory Model for Program Execution. Problem

Chapter 10 Memory Model for Program Execution Original slides by Chris Wilcox, Colorado State University Problem How do we allocate memory during the execution of a program written in C?! Programs need

### Programming Languages

Programming Languages Tevfik Koşar Lecture - XX April 4 th, 2006 1 Roadmap Subroutines Allocation Strategies Calling Sequences Parameter Passing Generic Subroutines Exception Handling Co-routines 2 1 Review

### Scope, 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)

### Procedures: Advanced Topics Chapter 12

Thi d t t d ith F M k 4 0 2 Procedures: Advanced Topics Chapter 12 The last chapter described how to create procedures, pass parameters, and allocate and access local variables. This chapter picks up where

### Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Carnegie Mellon Machine-Level Programming III: Procedures 15-213/18-213/14-513/15-513: Introduction to Computer Systems 7 th Lecture, September 18, 2018 Today Procedures Mechanisms Stack Structure Calling

### See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week

### ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

Supporting Procedures in Computer Hardware James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy