Chapter 10 And, Finally... The Stack

Similar documents
Lecture 14: Instruction Level Parallelism

Chapter 3: Computer Organization Fundamentals. Oregon State University School of Electrical Engineering and Computer Science.

CONTROL UNIT OMEGA 800-R. User manual

M2 Instruction Set Architecture

Welcome to ABB machinery drives training. This training module will introduce you to the ACS850-04, the ABB machinery drive module.

POWER and ELECTRIC CIRCUITS

Alternative Fuel Engine Control Unit

CS 152 Computer Architecture and Engineering

Welcome to the presentation about safety functions of ACS880 functional safety, FSO- 12 Safety functions module.

Simple Line Follower robot

Furnace Web Site FAQs. Pro Press 100 / Pro 100 / Pro 100 plus. Lift. Belt Noise

Lecture Secure, Trusted and Trustworthy Computing Trusted Execution Environments Intel SGX

TRAVEL CORDSET AND WALL STATION TEST REPORT

EE 6502 UNIT-II PROGRAMMING OF 8085 MICROPROCESSOR. Prepared by S.Sayeekumar, AP/RMDEEE

Advanced Superscalar Architectures. Speculative and Out-of-Order Execution

FabComp: Hardware specication

OPERATING MANUAL Digital Diesel Control Remote control panel for WhisperPower generator sets

Designing a Dual-Axis Solar Tracking System for increasing efficiency of a Solar Panel

Rev. 12/14/2001. PC-5500 PC-5750 Operation Manual

1. Historical background of I2C I2C from a hardware perspective Bus Architecture The Basic I2C Protocol...

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, S. McKee, E. Sirer, H. Weatherspoon]

TECHNICAL MANUAL FOR ELECTRONIC SPEEDOMETER STR-RIEJU MATRIX 2

RAM-Type Interface for Embedded User Flash Memory

Pressing and holding the + RES switch, when the Cruise Control System is engaged, will allow the vehicle to

In-Place Associative Computing:

Ramp Profile Hardware Implementation. User Guide

Hardware Design of Brushless DC Motor System Based on DSP28335

Touch plate serial number. Please save this info here for use later:

CUSTOMER - FREQUENTLY ASKED QUESTIONS

FLUID POWER FLUID POWER EQUIPMENT TUTORIAL PNEUMATIC CIRCUTS. This work covers part of outcome 3 of the Edexcel standard module:

The Discussion of this exercise covers the following points:

M:2:I Milestone 2 Final Installation and Ground Test

Issue 2.0 December EPAS Midi User Manual EPAS35

An ISO 9001:2008 Registered Company

TRIPS AND FAULT FINDING

CASTON OWNER S MANUAL

Chapter 45 Adaptive Cars Headlamps System with Image Processing and Lighting Angle Control

ALLURE BP320 by Norman

Troubleshooting. This section outlines procedures for troubleshooting problems with the operation of the system:

Frequently Asked Questions

Seeker HL Source Transmitter. User s Guide

The CMPE 118 Cockroach Robot Dept. of Computer Engineering, UCSC

Rover - Remote Operated Vehicle for Extraction and Reconnaissance

ST950 LRT Handbook 667/HB/46000/002

Exercise 6. Three-Phase AC Power Control EXERCISE OBJECTIVE DISCUSSION OUTLINE DISCUSSION. Introduction to three-phase ac power control

AR2000 Rheometer: Instructions

Flymentor 3D. User Manual SHENZHEN KDS MODEL TECHNOLOGIES CO.,LTD

ECHO Enhanced Controller Hook Count Application *** Infrared Photo Sensors *** GCA 110 ECHO Controller. Version 3.5

TRITON ERROR CODES ERROR CODE MODEL SERIES DESCRIPTION RESOLUTION

ITCEMS950 Idle Timer Controller - Engine Monitor Shutdown Isuzu NPR 6.0L Gasoline Engine

Session Four Applying functional safety to machine interlock guards

JUMO DSM software. PC software for management, configuration, and maintenance of digital sensors. Operating Manual T90Z001K000

Lingenfelter NCC-002 Nitrous Control Center Quick Setup Guide

BSR Magic Box Digital ignition control for 4, 6, or 8 cylinder engines

Tension Control Inverter

Vehicle Black Box System

BASIC MECHATRONICS ENGINEERING

Computer Architecture: Out-of-Order Execution. Prof. Onur Mutlu (editted by Seth) Carnegie Mellon University

QT CARTS PROGRAMMING AND TROUBLESHOOTING GUIDE FOR ELECTRONIC OR PROXIMITY LOCKS

ORA DATA REQUEST ORA-SCG-DR-035-SWC SOCALGAS 2016 GRC A SOCALGAS RESPONSE DATE RECEIVED: DECEMBER 31, 2014 DATE RESPONDED: JANUARY 16, 2015

DA-ST512 (Suspension Calibration Application) User s Manual

ED900. Low energy operator. Customizing Features: Book 3 of 3

CONTROLLER DIAGNOSTIC GUIDE

Photoillustration: Harold A. Perry; images: Thinkstock & Ford

Dynamics of Machines. Prof. Amitabha Ghosh. Department of Mechanical Engineering. Indian Institute of Technology, Kanpur. Module No.

CHAPTER 2. Current and Voltage

SINAMICS GM150 IGCT version

Spring Final Review. Collision Encounter Reduction for Unmanned Aerial Systems (CERUNAS) 29 April 2014

COSC 6385 Computer Architecture. - Tomasulos Algorithm

Linear/Gradient Flow Rate Ramping

Multi Core Processing in VisionLab

(for example A0) on the Arduino you can expect to read a value of 0 (0V) when in its upright position and 1023 (5V) when it is tilted.

Lecture 31 Caches II TIO Dan s great cache mnemonic. Issues with Direct-Mapped

Facility Employing Standard Converters for Testing DFIG Wind Generators up to 30kW

Parallelism I: Inside the Core

EEL Project Design Report: Automated Rev Matcher. January 28 th, 2008

Development of Power Conditioner with a Lithium Ion Battery

EPAS Desktop Pro Software User Manual

HEAVY-DUTY SIZE MODEL User/Caregiver Manual FOLD & GO Wheelchairs A Division of OneKubedDESIGNS, LLC.

Instructions Manual Control Unit RCU205

Fill-Drain Time Set up

Important instructions

VOLUMETRIC BLENDING SYSTEM OPERATION MANUAL

Bill of Materials: Car Battery/charging system diagnostics PART NO

DKG-705 AUTOMATIC MAINS FAILURE AND REMOTE START UNIT WITH PARALLEL TO MAINS AND DUAL GENSET PARALLEL FEATURES

NOS -36 Magic. An electronic timer for E-36 and F1S Class free flight model aircraft. January This document is for timer version 2.

2003 CVT when used with 2.2L L61 engine in the Saturn ION TRANSMISSION DIAGNOSTIC PARAMETERS

Abrites Diagnostics for Peugeot/ Citroën User Manual abrites.com

XC Instrumentation System Owner s Manual Revision /05/06

Computer Aided Transient Stability Analysis

SEDONA FRAMEWORK BEST OPPORTUNITY FOR OPEN CONTROL

Hardware installation guide

Park Smart. Parking Solution for Smart Cities

SDRAM DEVICE OPERATION

Implementing Photovoltaic Battery Charging System using C2000 Microcontrollers on Solar Explorer Kit

SPA MICROPROCESSOR COMBINED TACHO&SPEEDO/GAUGE INSTALLATION AND OPERATING MANUAL PAGE 2...INSTRUMENT FEATURES PAGE 3...OPERATING INSTRUCTIONS

ALIGNING A 2007 CADILLAC CTS-V

International Journal of Advance Engineering and Research Development

Controller Test Procedure

GE Programmable Control Products. PACSystems* RX3i Rackless Energy Pack IC695ACC403 Quick Start Guide. GFK-3000 December 2016

Transcription:

Chapter 10 And, Finally... The Stack

Stacks: An Abstract Data Type A LIFO (last-in first-out) storage structure. The first thing you put in is the last thing you take out. The last thing you put in is the first thing you take out. This means of access is what defines a stack, not the specific implementation. Two main operations: PUSH: add an item to the stack POP: remove an item from the stack 10-2

A Physical Stack Coin rest in the arm of an automobile 1995 1996 1998 1982 1995 1998 1982 1995 img src: edarts.net Initial State After One Push After Three More Pushes After One Pop First quarter out is the last quarter in. 10-3

A Hardware Implementation Data items move between registers Empty: Yes Empty: No Empty: No Empty: No TOP #18 TOP #12 TOP #31 TOP #5 #18 #31 #18 Initial State After One Push After Three More Pushes After Two Pops 10-4

A Software Implementation Data items don't move in memory, just our idea about where the TOP of the stack is. #12 TOP #12 #5 #5 #31 #31 TOP #18 TOP #18 #18 TOP x4000 R6 x3fff R6 x3ffc R6 x3ffe R6 Initial State After One Push After Three More Pushes After Two Pops By convention, R6 holds the Top of Stack (TOS) pointer. 10-5

Basic Push and Pop Code For our implementation, stack grows downward (when item added, TOS moves closer to 0) Push ADD R6, R6, #-1 ; decrement stack ptr STR R0, R6, #0 ; store data (R0) Pop LDR R0, R6, #0 ; load data from TOS ADD R6, R6, #1 ; increment stack ptr 10-6

Pop with Underflow Detection If we try to pop too many items off the stack, an underflow condition occurs. Check for underflow by checking TOS before removing data. Return status code in R5 (0 for success, 1 for underflow) POP LD R1, EMPTY ; EMPTY = -x4000 ADD R2, R6, R1 ; Compare stack pointer BRz FAIL ; with xc000 (= -x4000) LDR R0, R6, #0 ADD R6, R6, #1 AND R5, R5, #0 ; SUCCESS: R5 = 0 RET FAIL AND R5, R5, #0 ; FAIL: R5 = 1 ADD R5, R5, #1 RET EMPTY.FILL xc000 10-7

Push with Overflow Detection If we try to push too many items onto the stack, an overflow condition occurs. Check for overflow by checking TOS before adding data. Return status code in R5 (0 for success, 1 for overflow) PUSH LD R1, MAX ; MAX = -x3ffb ADD R2, R6, R1 ; Compare stack pointer BRz FAIL ; with xc005 (=-x3ffb) ADD R6, R6, #-1 STR R0, R6, #0 AND R5, R5, #0 ; SUCCESS: R5 = 0 RET FAIL AND R5, R5, #0 ; FAIL: R5 = 1 ADD R5, R5, #1 RET MAX.FILL xc005 10-8

Interrupt-Driven I/O (Part 2) Interrupts were introduced in Chapter 8. 1. External device raises an interrupt when it needs attention. 2. Processor saves state and starts service routine. 3. When finished, processor restores state and resumes program. Interrupt is an mysterious subroutine call, triggered by an external event. Chapter 8 didn t explain how (2) and (3) occur, because it involves a stack. Now, we re ready 10-9

Processor State What state is needed to completely capture the state of a running process? Memory Program Counter Pointer to next instruction to be executed. General-Purpose Registers (R0~R7) Processor Status Register Privilege [15], Priority Level [10:8], Condition Codes [2:0] P = 0: Supervisor Mode P = 1: User Mode Miscellaneous Registers: Saved.SSP, Saved.USP (will see next), etc 10-10

Supervisor Stack A special region of memory is used as the stack for interrupt service routines. Initial Supervisor Stack Pointer (SSP) stored in Saved.SSP. Another register for storing User Stack Pointer (USP): Saved.USP. Want to use R6 as stack pointer. So that our PUSH/POP routines still work. When switching from User mode to Supervisor mode (as result of interrupt), save R6 to Saved.USP. 10-11

Invoking the Service Routine The Details 1. If Priv = 1 (user), Saved.USP R6; R6 Saved.SSP. 2. Push PSR and PC to Supervisor Stack. 3. Set PSR[15] 0 (supervisor mode). 4. Set PSR[10:8] priority of interrupt being serviced. 5. Set PSR[2:0] 0. 6. Set MAR x01vv, where vv = 8-bit interrupt vector provided by interrupting device (e.g., keyboard = x80). 7. Load memory location (M[x01vv]) into MDR. 8. Set PC MDR; now first instruction of ISR will be fetched. Note: This all happens between the STORE RESULT of the last user instruction and the FETCH of the first ISR instruction (i.e., atomic) 10-12

Returning from Interrupt Special instruction RTI that restores state. 1. Pop PC from supervisor stack. (PC = M[R6]; R6 = R6 + 1) 2. Pop PSR from supervisor stack. (PSR = M[R6]; R6 = R6 + 1) 3. If PSR[15] = 1 (if previous mode is USER mode), R6 = Saved.USP. (If going back to user mode, need to restore User Stack Pointer.) RTI is a privileged instruction. Can only be executed in Supervisor Mode. If executed in User Mode, causes an exception. (More about that later.) 10-13

Example (1) S-SSP Program A Saved.SSP: Saved.USP: S-SSP???? x3006 ADD PC x3006 Executing ADD at location x3006 when Device B interrupts. 10-14

Example (2) Program A ISR for Device B Saved.SSP: Saved.USP: S-SSP R6-Saved x6200 R6 x3007 x3006 ADD PSR for A x6210 RTI PC x6200 Saved.USP = R6. R6 = Saved.SSP. Push PSR and PC onto stack, then transfer to Device B service routine (at x6200). 10-15

Example (3) Program A ISR for Device B Saved.SSP: Saved.USP: S-SSP R6-Saved R6 x3007 x3006 ADD x6200 x6202 AND PSR for A x6210 RTI PC x6203 Executing AND at x6202 when Device C interrupts. 10-16

Example (4) R6 x6203 PSR for B x3007 PSR for A x3006 Program A ADD x6200 x6202 ISR for Device B AND x6210 RTI Saved.SSP: Saved.USP: x6300 S-SSP R6-Saved ISR for Device C PC x6300 x6315 RTI Push PSR and PC onto stack, then transfer to Device C service routine (at x6300). 10-17

Example (5) x6203 PSR for B R6 x3007 PSR for A x3006 Program A ADD x6200 x6202 ISR for Device B AND x6210 RTI Saved.SSP: Saved.USP: x6300 S-SSP R6-Saved ISR for Device C PC x6203 x6315 RTI Execute RTI at x6315; pop PC and PSR from stack. 10-18

Example (6) S-SSP x6203 PSR for B x3007 PSR for A x3006 Program A ADD x6200 x6202 ISR for Device B AND x6210 RTI Saved.SSP: Saved.USP: x6300 S-SSP R6-Saved ISR for Device C PC x3007 x6315 RTI Execute RTI at x6210; pop PSR and PC from stack. Restore R6. Continue Program A as if nothing happened. 10-19

Exception: Internal Interrupt When something unexpected happens inside the processor, it may cause an exception. Examples: Executing an illegal opcode (e.g., 1101) Divide by zero Accessing an illegal address Executing RTI in the User mode Handled just like an interrupt Vector is determined internally by type of exception Priority is the same as the program that caused the exception 10-20

꼭기억해야할것 Stack: An Abstract Data Type Push Pop IsEmpty Interrupt Service Routine Invoked in response to an interrupt States of the program being interrupted are saved to / restored from the Supervisor Mode Stack We will see the use of the User Mode Stack soon Mechanisms to get attention from the operating system (OS) System calls (via TRAP instruction) Interrupts Exceptions (processed in the same way as interrupts) 10-21