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.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

Week 8 Stack and Subroutines. Stack  The stack is a section of data memory (or RAM) that is reserved for storage of temporary data  The data may represent.
Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
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.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Computer Organization and Architecture
Computer Organization and Architecture
Chapter 6 Limited Direct Execution
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.
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 7 Interupts DMA Channels Context Switching.
RapUp Dynamic Allocation of Memory in C Last HW Exercise Review for Final Final Exam Next Thursday – Same Time / Same Place.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Chapters 9 & 10 Midterm next Wednesday (11/19) Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET The Stack SSP & USP Interrupts RTI.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
CSS 372 Oct 2 nd - Lecture 2 Review of CSS 371: Simple Computer Architecture Chapter 3 – Connecting Computer Components with Buses Typical Bus Structure.
Chapter 9 Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
TCSS 372A Computer Architecture. Getting Started Get acquainted (take pictures) Review Web Page (
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.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
TCSS 372A Computer Architecture. Getting Started Get acquainted (take pictures) Purpose, scope, and expectations of the course Expectations & strategy.
COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.
Chapter 10 The Stack l Stack data structure l Interrupt I/O l Arithmetic using a stack.
CH12 CPU Structure and Function
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
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.
Instruction Set Architecture
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
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.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-3 Instruction Set Architecture ISA Overview Operate instructions Data.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
The Stack An Hong 2015 Fall School of Computer Science and Technology Lecture on Introduction to Computing Systems.
Chapter 10 And, Finally... The Stack
MICROPROCESSOR BASED SYSTEM DESIGN
The Stack.
Chapter 10 And, Finally... The Stack
Chapter 10 The Stack.
Arithmetic using a stack
BIC 10503: COMPUTER ARCHITECTURE
Chapter 10 And, Finally... The Stack
Presentation transcript:

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

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 Abstract Data Structures  are defined simply by the rules for inserting and extracting data The rule for a Stack is LIFO (Last In - First Out)  Operations:  Push (enter item at top of stack)  Pop (remove item from top of stack)  Error conditions:  Underflow (trying to pop from empty stack)  Overflow (trying to push onto full stack)  We just have to keep track of the 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 A “physical” stack A coin holder as a stack

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 A hardware stack Implemented in hardware (e.g. registers)  Previous data entries move up to accommodate each new data entry  Note that the Top Of Stack is always in the same place.

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 A software stack Implemented in memory  The Top Of Stack moves as new data is entered  Here R6 is the TOS register, a pointer to the Top Of Stack

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 Push  Decrement TOS pointer (our stack is moving down)  then write data in R0 to new TOS Pop  Read data at current TOS into R0  then increment TOS pointer PUSHADDR6, R6, # -1 STRR0, R6, # 0 POPLDRR0, R6, # 0 ADDR6, R6, # 1

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 (cont.) What if stack is already full or empty?  Before pushing, we have to test for overflow  Before popping, we have to test for underflow  In both cases, we use R5 to report success or failure

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-3 POP STR2, Sv2 ;save, needed by POP STR1, Sv1 ;save, needed by POP LDR1, BASE;BASE contains x-3FFF ADDR1,R1, # -1 ;R1 now has x-4000 ADDR2, R6, R1 ;Compare SP to x4000 BRzfail_exit;Branch if stack is empty LDRR0, R6, # 0 ;The actual ‘pop’ ADDR6, R6, # 1 ;Adjust stack pointer BRnzp success_exit

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-3 (cont.) PUSH STR2, Sv2 ;needed by PUSH STR1, Sv1 ;needed by PUSH LDR1, MAX;MAX has x-3FFB ADDR2, R6, R1 ;Compare SP to x4004 BRzfail_exit;Branch is stack is full ADDR6, R6, # -1;Adjust Stack Pointer STRR0, R6, # 0;The actual ‘push’

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-2 (cont.) success_exitLDR1, Sv1 ;Restore register values LDR2, Sv2 ; ANDR5, R5, # 0;R5 <-- success RET ; fail_exit LDR1, Sv1;Restore register values LDR2, Sv2 ANDR5, R5, # 0 ADDR5, R5, # 1;R5 <-- fail RET BASE.FILL xC001 ;Base has x-3FFF MAX.FILL xC005 ;Max has x-4004 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 Interrupt-driven I/O (again!) We can now finish servicing the interrupt!  Remember that an INT signal “hijacks” the CPU, diverting it without warning from processing the program.  We left two questions hanging in our earlier treatment of interrupt handling:  How do we save enough information about the current program to be able to pick up where we left off after servicing the interrupt? And  How do we reset the CPU to deal with the Interrupt Service Routine?  In both cases, the answer has to do with state (remember the Finite State Machine?), and the use of stacks.

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 The State of a Program State is a “snapshot” of the system  The complete state specification would include the contents of relevant memory locations, the general purpose registers, and some special registers, including the PC and … Introducing … the PSR  or Processor Status Register  which stores the most important pieces of information about the current program Pr ---PL--- N Z P Privilege Priority Level Condition codes

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 The PSR Privilege  PSR[15] indicates whether the current program is running in Supervisor (0) or User (1) mode  This allows some resources to be kept “off limits” to non-OS programs Priority  PSR[10:8] stores the priority level of the current program  There are 8 levels of priority, from PL0 (lowest) to PL7 (highest). Condition Codes  PSR[2:0] stores the current NZP condition codes

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 Saving the state - 1 We only need to save the PC and the PSR  We assume that the ISRs will be smart enough to save relevant Registers (remember “callee save”?)  The PC and the PSR between them hold enough state information to be able to reconstitute the program when needed. Where do we save them?  On a stack!  Remember, there might be nested interrupts, so simply saving them to a register or reserved memory location would not work.

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 The Supervisor Stack Only Supervisors can use the Supervisor Stack!  The User stack & the Supervisor stack are in separate regions of memory  The stack pointer for the current stack is always R6.  If the current program is in privileged mode, R6 points to the Supervisor stack, otherwise it points to the user stack.  Two special purpose registers, Saved.SSP and Saved.USP, are used to store the pointer currently not in use, so the two stacks can share push/pop subroutines without interfering with each other.

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 Saving the state - 2 When the CPU receives an INT signal …  The privilege mode changes from User to Supervisor mode  PSR[15] <= 0  The User stack pointer is saved & the Supervisor stack pointer is loaded  Saved.USP <= (R6)  R6 <= (Saved.SSP)  PC and PSR are pushed onto the Supervisor Stack  Now the CPU is free to handle the interrupting device!

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 Loading the state of the ISR Vectored interrupts  Along with the INT signal, the I/O device transmits its priority level and an 8-bit vector (INTV).  If the interrupt is accepted, INTV is expanded to a 16-bit address:  The Interrupt Vector Table resides in locations x0100 to x01FF and holds the starting addresses of the various Interrupt Service Routines. (similar to the Trap Vector Table and the Trap Service Routines)  INTV is an index into the Interrupt Vector Table, i.e. the address of the relevant ISR is ( x Zext(INTV) )  The address of the ISR is loaded into the PC  The PSR is set as follows:  PSR[15] <= 0 (Supervisor mode)  PSR[10:8] is set to the priority level of the interrupting device  PSR[2:0] <= 000 (no condition codes set)

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 Returning from the Interrupt The last instruction of an ISR is RTI  Return from Interrupt (opcode 1000)  Pops PSR and PC from the Supervisor stack  Restores the condition codes from PSR  If necessary (i.e. if the current privilege mode is User) restores the user stack pointer to R6 from Saved.USP  Continues running the program as if nothing had happened!

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 Interrupts illustrated

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 Supervisor Stack & PC during INT

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 as an alternative to Registers Three-address vs zero-address  The LC-3 explicitly specifies the location of each operand: it is a three-address machine  e.g. ADD R0, R1, R2  Some machines use a stack data structure for all temporary data storage: these are zero-address machines  the instruction ADD would simply pop the top two values from the stack, add them, and push the result back on the stack  Most calculators use a stack to do arithmetic, most general purpose microprocessors use a register bank