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.

Slides:



Advertisements
Similar presentations
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Advertisements

Computer Architecture CSCE 350
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
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.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Run-Time Storage Organization
Intro to Computer Architecture
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
7/13/20151 Topic 3: Run-Time Environment Memory Model Activation Record Call Convention Storage Allocation Runtime Stack and Heap Garbage Collection.
Chapter 8 :: Subroutines and Control Abstraction
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Higher Level languages have adopted a standard Referred to as C-style calling Uses the stack.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
Runtime Stack Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens MIPS Memory Organization In addition to memory for static.
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
CSC 8505 Compiler Construction Runtime Environments.
Pushing the Return Address To return to the caller a subroutine must have the correct return address in $ra when the jr instruction is performed. But this.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter 14 Functions.
Computer Architecture & Operations I
Lecture 7 Macro Review Stack Frames
Computer Science 210 Computer Organization
MIPS Assembly Language Programming
© Craig Zilles (adapted from slides by Howard Huang)
CSCI206 - Computer Organization & Programming
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
The Stack.
Lecture 4: MIPS Instruction Set
Procedures (Functions)
Procedures (Functions)
Functions and Procedures
Chapter 9 :: Subroutines and Control Abstraction
CSCI206 - Computer Organization & Programming
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Stack Frame Linkage.
MIPS Instructions.
The University of Adelaide, School of Computer Science
MIPS Functions.
Lecture 5: Procedure Calls
MIPS Procedures.
Topic 3-a Calling Convention 1/10/2019.
10/4: Lecture Topics Overflow and underflow Logical operations
Program and memory layout
Program and memory layout
Runtime Environments What is in the memory?.
Computer Architecture
Program and memory layout
Where is all the knowledge we lost with information? T. S. Eliot
Program and memory layout
© Craig Zilles (adapted from slides by Howard Huang)
MIPS Functions.
Topic 2b ISA Support for High-Level Languages
Implementing Functions: Overview
Presentation transcript:

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 stack Automatic Variables "automatically" pushed and popped as a subroutine is entered and exited On the heap. Dynamic Variables

Frames in the Run Time Stack In a high-level language a local variable is implemented as a location on the run-time stack. Each time a subroutine is activated, new locations for variables are pushed onto the stack. The section of the stack for each activation is called a stack frame or an activation record. When a subroutine returns to its caller the stack frame is popped from the stack. Thus, local variables only exist as memory locations while a subroutine is active.

Implementation of Local Variables In this example, space is reserved in the stack for implementing four local variables a, b, i and j. In the picture, the space reserved for variable a is labeled "a", but of course what is in that space is the 32-bit pattern that the variable holds. The values stored in a variable may change as the program executes. A frame pointer holds the address of the stack frame for a subroutine.

$fp – is not changed. $sp – is changed Register $30 is reserved, by software convention, for use as a frame pointer. When a subroutine starts running, the frame pointer and the stack pointer contain the same address. While the subroutine is active, the frame pointer, points at the top of the stack. (Doesn’t change). The stack pointer may be involved in pushing and popping values onto and off of the stack. (Changed)

Frame-based Linkage Convention Calling a Subroutine (done by the caller): Push any registers $t0-$t9 that contain values that must be saved. Push the registers in numerical order. Put argument values into $a0-$a3. Call the subroutine using jal. Subroutine Prolog (done by the subroutine): Push $ra (always). Push the caller's frame pointer $fp. Push any of the registers $s0-$s7 that the subroutine might alter. Initialize the frame pointer: $fp = $sp - space_for_variables. Initialize the stack pointer: $sp = $fp.

Frame-based Linkage Convention  Body: Normal code, except it must follow these conventions if it calls another subroutine. T and A registers can be used freely, as can any S registers that were saved in the prolog. Variables on the stack are accessed using disp($fp). The subroutine may push and pop values on the stack using $sp.

Frame-based Linkage Convention  Epilog: Put return values in $v0-$v1 registers. $sp = $fp + space_for_variables. Pop into $s0-$s7 any values for them that were previously saved in the frame. Pop the caller's frame pointer into $fp. Pop $ra (always). Return to the caller using jr $ra. Regaining Control: Pop any registers $t0-$t9 that the caller previously pushed