Yung-Hsiang Lu Purdue University

Slides:



Advertisements
Similar presentations
Program Memory MIPS memory operations Getting Variable Addresses Advanced structures.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Introduction to Programming Lecture 39. Copy Constructor.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Chapter 10 More on Modular Programming and Functions.
Pointers: Part I. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
ESP int f(int x) {.... } int g(int y) { …. f(2); …. } int main() { …. g(1); …. } EIP 100: 200: 250: 300: 350:
CMPE13Cyrus Bazeghi Chapter 14 Functions in C. CMPE13 2 Functions Smaller, simpler, subcomponents of programs Provide abstraction –hide low-level details.
Runtime Environments Compiler Construction Chapter 7.
Recursion Concepts Implementation Data Structures and Algorithms in Java, Third EditionCh05 – 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dynamic Memory Allocation 9.8.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
CSCI 125 & 161 / ENGR 144 Lecture 16 Martin van Bommel.
Windows Programming Lecture 03. Pointers and Arrays.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Recap Resizing the Vector Push_back function Parameters passing Mechanism Primitive Arrays of Constants Multidimensional Arrays The Standard Library string.
Defining Your Own Classes II
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Assembly function call convention
Pointers.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Understand argc and argv
Pointers in C.
Structure of C Programs
Chapter 3: Using Methods, Classes, and Objects
Checking Memory Management
Chapter 14 Functions.
Java Review: Reference Types
CSI-121 Structured Programming Language Lecture 16 Pointers
Introduction to Pointers
Introduction to Pointers
Stack Memory 1 (also called Call Stack)
Introduction to the C Language
Yung-Hsiang Lu Purdue University
CS 240 – Lecture 5 Scope of Variables, The Stack, Automatic Variables, Global Variables, Constant Type.
Stack Memory 2 (also called Call Stack)
Dynamic Memory A whole heap of fun….
The University of Adelaide, School of Computer Science
Understanding Program Address Space
Dynamic Memory Allocation (and Multi-Dimensional Arrays)
Dynamic Memory A whole heap of fun….
AKA the birth, life, and death of variables.
CS111 Computer Programming
Pointers Lecture 1 Thu, Jan 15, 2004.
Observing how the machine acts
Passing Arguments and The Big 5
Dynamic Memory A whole heap of fun….
C Programming Lecture-8 Pointers and Memory Management
The Stack.
Introduction to Pointers
Pointers, Dynamic Data, and Reference Types
Classes and Objects Object Creation
Chapter 14 Functions.
Introduction to Pointers
Chapter 14 Functions.
Presentation transcript:

Yung-Hsiang Lu Purdue University Stack Memory 3 Yung-Hsiang Lu Purdue University

Stack Memory may store three things: return location arguments local variables

Memory is "address-value" pairs Memory is organized into rows. Each row has an address and stores a value. The addresses are always distinct. You can think of the addresses in memory as home addresses and the values are the names of the families living at that address Address Value 001 C Language 002 Year 2016 003 5 004 36.97 Taylor Smith Johnson

Some Rules about Addresses Addresses are assigned by operating systems Two different pieces of information have different addresses, guaranteed by operating systems A programmer has no control of the address given by the operating system "Zero" is never a valid address. C programs has a special symbol (NULL) for this address.

Value Address Frame of f3 106 z = 3.2 105 y = 7 104 VA 102 103 line 5 void f1(int x) 2 { 3 int a; 4 a = f3(7, 3.2); 5 ... 6 7 } 8 int f3(int y, double z) 9 10 11 return ... Frame of f3 106 z = 3.2 105 y = 7 104 VA 102 103 line 5 Frame of f1 102 a = 101 x = 100 line ?

Memory Organization Frame Symbol Address Value f3 z 106 3.2 y 105 7 VA void f1(int x) 2 { 3 int a; 4 a = f3(7, 3.2); 5 ... 6 7 } 8 int f3(int y, double z) 9 10 11 return ... Frame Symbol Address Value f3 z 106 3.2 y 105 7 VA 104 102 RL 103 line 5 f1 a x 101 100 line ? RL: return location VA: value address

Frames and Symbols for Humans Computers Know Only Addresses and Values

Memory Organization Frame Symbol Address Value f3 z 106 3.2 y 105 7 VA For Humans 1 void f1(int x) 2 { 3 int a; 4 a = f3(7, 3.2); 5 ... 6 7 } 8 int f3(int y, double z) 9 10 11 return ... Frame Symbol Address Value f3 z 106 3.2 y 105 7 VA 104 102 RL 103 line 5 f1 a x 101 100 line ? RL: return location VA: value address

Stack Memory may store three things: return locations arguments local variables value addresses