Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation.

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Chapter 17 Recursion. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Mathematical Definition: RunningSum(1)
Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
S. Barua – CPSC 240 CHAPTER 10 THE STACK Stack - A LIFO (last-in first-out) storage structure. The.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
Chapters 9 & 10 Midterm next Wednesday (11/19) Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET The Stack SSP & USP Interrupts RTI.
Data Structures from Cormen, Leiserson, Rivest & Stein.
Chapter 9 Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET.
Copyright © The McGraw-Hill Companies, Inc
Chapter 9 Trap Routines TRAP number (go to service routine) & RET (return from service routine) Subroutines (or Functions) JSR offset or JSRR rn (go to.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University.
Chapter 10 The Stack l Stack data structure l Interrupt I/O l Arithmetic using a stack.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 2 Bits, Data Types & Operations Integer Representation Floating-point Representation.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
Chapter 14 Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Function Smaller, simpler, subcomponent.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Chapter 10 And, Finally... The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 3 Digital Logic Structures Transistors Logic gates & Boolean logic Combinational.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 3 Digital Logic Structures Transistors Logic gates & Boolean logic Combinational.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-2 Instruction Set Architecture Operate instructions Data Movement instructions.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
17.16 Synthesis of Thyroid Hormone (TH) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slide number: 1.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-3 Instruction Set Architecture ISA Overview Operate instructions Data.
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Data Movement Instructions Load --
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Memory and Data Structures Patt and Patel Ch. 10 & 16.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
Chapter 14 Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Declarations (aka prototype) int.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Interrupt I/O (again!) Arithmetic using a stack.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
The Stack An Hong 2015 Fall School of Computer Science and Technology Lecture on Introduction to Computing Systems.
Chapter 10 And, Finally... The Stack
Chapter 14 Functions.
STACKS & QUEUES for CLASS XII ( C++).
Computer Architecture & Operations I
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.
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Dr. Bernard Chen Ph.D. University of Central Arkansas
Lab 3 - Branching & Subroutines
Chapter 10 And, Finally... The Stack
Chapter 10 The Stack.
Arithmetic using a stack
The University of Adelaide, School of Computer Science
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Chapter 10 And, Finally... The Stack
HKN ECE 220: Fall 2018 Midterm 1 Andrew Fortunat, Jeff Chang, Srijan Chakraborty, Kanad Sarkar February 16, 2019.
Chapter 17 Recursion.
Implementing Functions: Overview
Presentation transcript:

Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation (Chapter 14)

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Stack Data Structure LIFO (last in - first out)  Operations:  Push (enter item at top of stack)  Pop (remove item from top of stack)  Error conditions:  Underflow (try to pop from empty stack)  Overflow (try to push onto full stack)  A register (eg. R6) holds address of top of stack (TOS)

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside PUSH & POP POP, including underflow check If (( TOS - EMPTY) == 0) R5 = 1 /* R5 gets error code */ Else { R0 = C[TOS]; /*R0 gets value at TOS*/ TOS = TOS - 1; R5 = 0; PUSH, including overflow check If (( TOS - MAX) == 0) R5 = 1 /* R5 gets error code */ Else { TOS = TOS + 1; C[TOS] = r0; /*TOS gets value in R0*/ R5 = 0; EMPTY TOS MAX

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside PUSH & POP in LC POP ST R2,Sv2 ;save, needed by POP ST R1,Sv1 ;save, needed by POP LD R1,BASE ;BASE contains -x4000 ADD R1,R1,#1 ;R1 has -x3FFF ADD R2,R6,R1 ;Compare SP to 3FFF BRz fail ;Branch if stk empty LDR R0,R6,#0 ;The actual ‘pop’ ADD R6,R6,#-1 ;Adjust stack pointer BRnzp success BASE.FILL xC000 ;Base has -x4000 MAX.FILL xBFFC ;Max has -x4004

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside PUSH & POP in LC PUSH ST R2,Sv2 ;needed by PUSH ST R1,Sv1 ;needed by PUSH LD R1,MAX ;MAX has ADD R2,R6,R1 ;Compare SP to x4004 BRz fail ;Branch is stk full ADD R6,R6,#1 ;Adjust SP STR R0,R6,#0 ;The actual ‘push’ Sv1.FILL x0000 Sv2.FILL x0000

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside PUSH & POP in LC success LD R1,Sv1 ;Restore reg values LD R2,Sv2 ; AND R5,R5,#0;R5 <-- success RET ; fail LD R1,Sv1;Restore reg values LD R2,Sv2 AND R5,R5,#0 ADD R5,R5,#1;R5 <-- fail RET

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Activation Records A Record  A collection of contiguous memory locations treated as one entity  The struct construct in C/C++ describes a record Activation Record  Is allocated for each function invocation in memory  The area of memory where activation records are allocated is called the stack memory  In LC-2, R6 is the stack pointer: it points to the top of the stack (TOS)  Each element on the stack is an activation record

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Activation Record return address return value dynamic link a b x y z Formal parameters Local variables function This (int a, int b) { int x, y, z; ……… function body …….. return z; }

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Example function This (int a, int b) { int x, y, z; ……… y = That(a); …….. return z; } function That (int a) { int x; ……… body …….. return x; }

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Example - 2 return address return value dynamic link a b x y z activation record of This R6 return address return value dynamic link a b x y z return address activation record of This x4050 a x return value activation record of That R6 x4050 When This is executing After This calls That When That terminates