ENERGY 211 / CME 211 Lecture 25 November 17, 2008.

Slides:



Advertisements
Similar presentations
1 Procedural Programming Paradigm Stacks and Procedures.
Advertisements

1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
DSP Implementation Lecture 3. Anatomy of a DSP Project In VDSP Linker Description File (.LDF) Source Files (.asm,.c,.h,.cpp,.dat) Object Files (.doj)
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
COMP3221: Microprocessors and Embedded Systems Lecture 12: Functions I Lecturer: Hui Wu Session 2, 2005.
Stacks and HeapsCS-3013 A-term A Short Digression on Stacks and Heaps CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Digression on Stack and Heaps CS-502 (EMC) Fall A Short Digression on Stacks and Heaps CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
Chapter 11-14, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3 Please return breadboards.
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Stacks and HeapsCS-502 Fall A Short Digression Stacks and Heaps CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
C Stack Frames / Pointer variables Stack: Local Variables Pass & Return values Frame Ptr linkage (R5) and PC linkage (R7) Pointer Variables: Defining &
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Stacks and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Software Development and Software Loading in Embedded Systems.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Runtime Environments Compiler Construction Chapter 7.
Compiler Construction
Stack Stack Pointer A stack is a means of storing data that works on a ‘Last in first out’ (LIFO) basis. It reverses the order that data arrives and is.
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
Basic Semantics Associating meaning with language entities.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
CSC 8505 Compiler Construction Runtime Environments.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Embedded Real-Time Systems
Lecture 3 Translation.
Dynamic Allocation in C
Writing Functions in Assembly
Memory Management Functions
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.
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Writing Functions in Assembly
In this lecture Global variables Local variables System stack
CMSC 341 Prof. Michael Neary
Chapter 9 :: Subroutines and Control Abstraction
The University of Adelaide, School of Computer Science
What time is it?. What time is it? Major Concepts: a data structure model: basic representation of data, such as integers, logic values, and characters.
UNIT V Run Time Environments.
Introduction to Computer Systems
Run Time Environments 薛智文
Runtime Environments What is in the memory?.
PROGRAM AT RUNTIME Subject code: CSCI-620
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
A Top-Level View Of Computer Function And Interconnection
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Run-time environments
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Topic 2b ISA Support for High-Level Languages
SPL – PS2 C++ Memory Handling.
Presentation transcript:

ENERGY 211 / CME 211 Lecture 25 November 17, 2008

What a CPU does Processing of code and data obtained from main memory Components: Registers: for storing data currently in use, and maintaining key addresses, such as the program counter, or PC (address of current instruction) ALU (Arithmetic-Logic Unit): performs actual operations on data in registers Instruction Decoder: determines from code what operations the ALU will perform MMU (Memory Management Unit): manages transfer of code and data between main memory, registers, and instruction decoder

Stacks and Registers A stack is a data structure that maintains a list of objects in a "last-in, first-out" manner (LIFO) Operations: push places an object on top of the stack, pop removes it Blocks of memory used by functions (called activation records) are maintained in a stack The record on top of the stack represents the function currently executing; next record is for the function that called it, etc. Location of top of the stack is maintained in a register called the stack pointer

Calling Functions When a function is called, its activation record is constructed and placed on top of a stack in the program's memory Record typically contains: values of arguments space for a return value space for local variables data needed to resume calling function after current function returns (such as PC value when function was called) When function exits, record is popped

Passing Arguments If arguments are passed by value, then values are copied to the activation record of the called function If arguments are passed by reference, then their addresses are copied, and code will dereference to access values C uses pass-by-value FORTRAN uses pass-by-reference C++ uses both C/C++ support variable length argument lists, where function call determines size of activation record at runtime, not compile time

Allocating on the Stack Local variables inside functions are allocated on the program's stack, within function activation records Allocation involves moving the stack pointer by the size of the variable, to create space for the variable and push it onto the stack When function exits, stack pointer is moved back, popping the variable, which goes away Uninitialized variables contain whatever data was previously there (garbage!) Large arrays should not be allocated on the stack, because stack space is quite limited

Static Allocation Program's memory contains an area for variables that persist throughout a program's execution Examples: static or global variables Locations and allocations determined at compile time Global variables accessible to all functions in the program, but must be declared In one file, declare normally In other files that use it, precede declaration with extern keyword Otherwise, name conflict might result, causing strange behavior at linking time

Allocating on the Heap The heap is a portion of a program's memory reserved for dynamic allocations Heap space is limited, so repeated allocations without de-allocating unused space will eventually result in failed allocations If pointer allocated with new is a local variable, and is not deleted or assigned elsewhere before function exits, NO chance of deleting it later, causing a memory leak Unless such a pointer is needed elsewhere, use a smart pointer

Compilers, Linkers, Loaders A compiler translates source code text (from .cpp files) into object code (.o files) Object code is relocatable so that it can be placed anywhere in main memory and work A linker assembles object code from several .o files into an executable file Using g++ or MDS's build function normally performs both compiling and linking A loader reads an executable file into main memory, so that code and data can be sent to the CPU for execution

Next Time More on Computer Organization Libraries Interpreted languages Software Engineering Basics Software life-cycle Coding conventions