Runtime Stack Activation record for hanoi;

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

The University of Adelaide, School of Computer Science
10/6: Lecture Topics Procedure call Calling conventions The stack
Procedures in more detail. CMPE12cGabriel Hugh Elkaim 2 Why use procedures? –Code reuse –More readable code –Less code Microprocessors (and assembly languages)
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Procedure call frame: Hold values passed to a procedure as arguments
CSE 5317/4305 L7: Run-Time Storage Organization1 Run-Time Storage Organization Leonidas Fegaras.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Procedures in more detail. CMPE12cCyrus Bazeghi 2 Procedures Why use procedures? Reuse of code More readable Less code Microprocessors (and assembly languages)
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
CS 536 Spring Code generation I Lecture 20.
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Lecture 6: Procedures (cont.). Procedures Review Called with a jal instruction, returns with a jr $ra Accepts up to 4 arguments in $a0, $a1, $a2 and $a3.
Intro to Computer Architecture
Run time vs. Compile time
Chapter 9 Procedures. Why use procedures? ? Microprocessors (and assembly languages) provide only minimal support for procedures Must build a standard.
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See P&H 2.8 and 2.12.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
Runtime Environments Compiler Construction Chapter 7.
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Program Compilation and Execution. Today’s Objectives Explain why runtime stack needed for C Explain why runtime stack needed for C Draw logical division.
1 Run-Time Environments. 2 Procedure Activation and Lifetime A procedure is activated when called The lifetime of an activation of a procedure is the.
Lesson 13 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Procedures. Why use procedures? ? Microprocessors (and assembly languages) provide only minimal support for procedures Must build a standard form for.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Activation Records (in Tiger) CS 471 October 24, 2007.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CSC 8505 Compiler Construction Runtime Environments.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
The Stack. ARMSim memory space: 0x Unused 0x x11400 Stack 0x x09400 Heap 0x?????-0x01400 Data 0x x????? Text 0x x01000.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
1 Topic 6: Activation Records COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer.
Procedures Procedures are very important for writing reusable and maintainable code in assembly and high-level languages. How are they implemented? Application.
Computer Architecture & Operations I
Lecture 7 Macro Review Stack Frames
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Run-Time Environments Chapter 7
Computer structure: Procedure Calls
MIPS Assembly Language Programming
COMPILERS Activation Records
The Stack.
Introduction to Compilers Tim Teitelbaum
Procedures (Functions)
Procedures (Functions)
Run-Time Environments
Prof. Hakim Weatherspoon
Activation Records and Function Calls
Prof. Hakim Weatherspoon
Application Binary Interface (ABI)
Stack Frame Linkage.
MIPS Instructions.
Understanding Program Address Space
Run-Time Environments
Program and memory layout
Procedures and Calling Conventions
Program and memory layout
Runtime Environments What is in the memory?.
Program and memory layout
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
Presentation transcript:

Runtime Stack Activation record for hanoi; 1 2 3 1 Activation record for main

Support for Function Calls Call usually simple, but setup not call printf what comes before and after call? Support recursion? No --- simple, use static space Yes --- runtime stack of activation record(s) Return value(s)

Activation Record Information Parameters Locals Compiler Temporaries Register Save/Restore Previous Activation Record Previous Scope Anything else?

A Function Call Convention fp and sp defined by assembler Caller function (in order) push parameters on stack, in reverse push fp fp = sp - 4 call callee fp = 0 (fp) sp = sp – (size of arguments + 4) Callee function (in order) sp = sp + size of function execute function sp = sp – size of function return

An Activation Record sp fp Next stack location – beyond the stack Reg save … Reg save … Reg save … Temps … 8(fp) – local 2 4(fp) – local 1 fp 0(fp) – old fp -4(fp) – parameter 1 -8(fp) – parameter 2 -12(fp) – parameter 3

Function Call Convention (2) Alpha conventions Parameters passed in registers, r16 - r24 or d16 - d24 Return in r0 (or d0) Registers r1 - r8, d1 - d8 are NOT saved across function call invocations (caller save) Registers r25 - r31 and d25 - d31 ARE saved across function call invocations (callee save)