Chapter 8 Input/Output I/O basics Keyboard input Monitor output

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
I/O Unit.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Overview I/O – memory mapped programmed / interrupt driven Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
Chapter 9 Overview Traps mechanism & RET Subroutines & JSR & JSRR & RET Interrupt mechanism & RTI.
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,
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,
S. Barua – CPSC 240 CHAPTER 8 I/O How are I/O devices identified? Memory-mapped vs. special instructions.
Overview Projects The Assembly Process Programmed I/O Interrupt Driven I/O.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
Chapter 8 I/O Programming Chapter 9 Trap Service Routines Programmed I/O Interrupts Interrupt Driven I/O Trap Service Routines.
Chapter 8 Overview Programmed I/O Interrupt Driven I/O.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Chapter 8 Input/Output l I/O basics l Keyboard input l Monitor output l Interrupt driven I/O l DMA.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Computer Architecture Lecture10: Input/output devices Piotr Bilski.
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,
2009 Sep 10SYSC Dept. Systems and Computer Engineering, Carleton University F09. SYSC2001-Ch7.ppt 1 Chapter 7 Input/Output 7.1 External Devices 7.2.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
I/O Organization Competency – C6. Important facts to remember when I/O devices are to be connected to CPU There is a vast variety of I/O devices. Some.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Chapter 8 Input/Output An Hong 2015 Fall School of Computer Science and Technology Lecture on Introduction to.
Input / Output Chapter 9.
Computer Science 210 Computer Organization
Chapter 8 I/O.
Microprocessor Systems Design I
HKN ECE 220: Fall 2017 Midterm 1 AJ Schroeder, Evan Lissoos, Utsav Kawrani 23rd September, 2017.
Computer Architecture
Computer Science 210 Computer Organization
Interrupts In 8085 and 8086.
Introduction of microprocessor
COSC121: Computer Systems: LC3 I/O (Intro)
Computer Science 210 Computer Organization
Chapter 8 I/O.
Computer Architecture
Chapter 8 I/O.
Computer System Overview
Computer Science 210 Computer Organization
HKN ECE 220: Spring 2018 Midterm 1
Introduction to Computer Engineering
Chapter 9 TRAP Routines and Subroutines
Chapter 8 I/O.
Introduction to Computer Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
TRAP Routines Privileged Instructions Subroutines
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Chapter 8 I/O.
Chapter 8 Input/Output An Hong 2016 Fall
COMP3221: Microprocessors and Embedded Systems
Chapter 13: I/O Systems.
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Chapter 8 Input/Output I/O basics Keyboard input Monitor output Interrupt driven I/O DMA

I/O Basics Definitions LC-3 supports only a keyboard and a monitor Input transfer data from the outside world to the computer: keyboard, mouse, scanner, bar-code reader, etc. Output transfer data from the computer to the outside: monitor, printer, LED display, etc. Peripheral: any I/O device, including disks. LC-3 supports only a keyboard and a monitor

Device Registers I/O Interface LC-3 Through a set of Device Registers: Status register (device is busy/idle/error) Data register (data to be moved to/from device) The device registers have to be read/written by the CPU. LC-3 KBDR: keyboard data register KBSR: keyboard status register DDR: display data register DSR: display status register KBSR[15] - keyboard ready (new character available) KBDR[7:0] - character typed (ASCII) DSR[15] - monitor ready DDR[7:0] - character to be displayed (ASCII) LC-3 KBSR KBDR DSR DDR

Addressing Device Registers Special I/O Instructions Read or write to device registers using specialized I/O instructions. Memory Mapped I/O Use existing data movement instructions (Load & Store). Map each device register to a memory address (fixed). CPU communicates with the device registers as if they were memory locations. LC-3 Uses memory mapped I/O: xFE00 KBSR Keyboard Status Register xFE02 KBDR Keyboard Data Register XFE04 DSR Display Status Register XFE06 DDR Display Data Register XFFFE MCR Machine Control Register

Memory-mapped Input

Memory-mapped Output

Synchronizing CPU and I/O Problem Speed mismatch between CPU and I/O: CPU runs at up to 2 GHz, while all I/O is much slower. Example : Keyboard input is both slow, and irregular. We need a protocol to keep CPU & KBD synchronized. Two possible solutions: Polling (handshake synchronization) Interrupt-driven I/O

Synchronizing CPU and I/O - 2 Polling, or handshake synchronization CPU checks the KBD Ready status bit. If set, CPU reads the data register and resets the Ready bit. Start over. Makes CPU-I/O interaction seem to be synchronous. Interrupt-driven I/O An external device is allowed to interrupt the CPU and demand attention The CPU attends to the device in an orderly fashion (more later)

Polling v/s Interrupts (Who’s driving?) Polling: CPU in charge CPU checks the ready bit of status register (as per program instructions). If (KBSR[15] == 1) then load KBDR[7:0] to a register. If the I/O device is very slow, CPU is kept busy waiting. Interrupt: peripheral in charge Event triggered - when the I/O device is ready, it sets a flag called an interrupt. When an interrupt is set, the CPU is forced to an interrupt service routine (ISR) which services the interrupting device. There can be different priority levels of interrupt. Specialized instructions can mask an interrupt level.

Polling Algorithm Input (keyboard) Output (monitor) The CPU loops checking the Ready bit When bit is set, a character is available CPU loads the character waiting in the keyboard data register Output (monitor) CPU loops checking the Ready bit When bit is set, display is ready for next character CPU stores a character in display data register

Polling details Keyboard Monitor When key is struck ASCII code of character is written to KBDR[7:0] (least significant byte of data register). KBSR[15] (Ready Bit) is set to 1. Keyboard is locked until CPU reads KBDR. The CPU sees Ready Bit, reads KBDR, and clears the Ready Bit, unlocking the keyboard. Monitor When CPU is ready to output a character CPU checks DSR[15] (Ready Bit) until it is set to 1 CPU writes character to DDR[7:0] Monitor sets DSR[15] to 0 while it is busy displaying the character, then sets it back to 1 to indicate readiness for next character.

Simple Polling Routines START LDI R1, A ;Loop if Ready not set BRzp START LDI R0, B ;If set, load char to R0 BR NEXT_TASK A .FILL xFE00 ;Address of KBSR B .FILL xFE02 ;Address of KBDR Input a character from keyboard START LDI R1, A ;Loop if Ready not set BRzp START STI R0, B ;If set, send char to DDR BR NEXT_TASK A .FILL xFE04 ;Address of DSR B .FILL xFE06 ;Address of DDR Output a character to the monitor

Keyboard Echo: combine the above START LDI R1,KBSR ;Loop if KB not ready BRzp START LDI R0,KBDR ;Get character ECHO LDI R1,CRTSR ;Loop if monitor not ready BRzp ECHO STI R0,CRTDR ;Send character BR NEXT_TASK KBSR .FILL xFE00 ;Address of KBSR KBDR .FILL xFE02 ;Address of KBDR DSR .FILL xFE04 ;Address of DSR DDR .FILL xFE06 ;Address of DDR

Example: Print a string LEA R1, STR ;Load address of string LOOP LDR R0, R1, #0 ;get next char to R0 BRZ DONE ;string ends with 0 LP2 LDI R3, DSR ;Loop until MON is ready BRzp LP2 STI R0, DDR ;Write next character ADD R1, R1, #1 ; Set address to next char BR LOOP STR .STRINGZ "Char String" DONE HALT

Interrupt-driven I/O Generating the interrupt signal The I/O device must want to request service. The device must have the right to request service, This request must be more urgent than the processor’s current task. Handling the interrupt signal We will wait untile we understand stacks before getting to this.

Generating the Interrupt Using the Status Register The peripheral sets a Ready bit in SR[15] (as with polling) The CPU sets an Interrupt Enable bit in SR[14] These two bits are anded to set the Interrupt. In this way, the CPU has the final say in who gets to interrupt it!

Priority Each task has an assigned priority level LC-3 has levels PL0 (lowest) to PL7 (highest). If a higher priority task requests access, a lower priority task will be suspended. Likewise, each device has an assigned priority The highest priority interrupt is passed on to the CPU only if it has higher priority than the currently executing task. If an INT is present at the start of the instruction cycle, an extra step is inserted: The CPU saves its state information so that it can later return to the current task. The PC is loaded with the starting address of the Interrupt Service Routine The FETCH phase of the cycle continues as normal.

Device Priority

Interrupts - More Another method of enabling devices to interrupt is the Interrupt mask register: each bit specifies whether the corresponding device is allowed to interrupt. In the CPU, the control logic checks the INT bit before each instruction fetch stage. If INT is set: CPU State information & PC are saved PC  address of corresponding ISR Change mask settings (allow nested interrupts) ISR is executed Reset mask settings Saved CPU state & PC are restored How can CPU tell who interrupted? Interrupt mask register Interrupt lines CPU INT

Interrupt – Who called? How can CPU tell who interrupted? Polling Vectored Interrupts Multiple CPU INT lines, each dedicated to a device or group of devices (Intel: INT0, INT1 …) Each INT line sends the CPU to a specific ISR (Interrupt Service Routine). The ISR must figure out who called if more than one device is associated with that INT line. Daisy Chain CPU sends an interrupt acknowledge (IACK) that is passed from one device to another. Interrupting device puts the address of its ISR on the Data Bus. Order of devices in the chain is the priority. Example: SCSII, USB Data bus IACK

Memory-mapped I/O revisited

DMA – Direct Memory Access A device specialized in transferring data between memory and an I/O device (disk). CPU writes the starting address and size of the region of memory to be copied, both source and destination addresses. DMA does the transfer in the background. It accesses the memory only when the CPU is not accessing it (cycle stealing). I/O Dev CPU memory DMA