The slides must be understood in Lecture 5

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Input and Output CS 215 Lecture #20.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Basic Input/Output Operations
Introduction to Interrupts
CHAPTER 9: Input / Output
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
System Calls 1.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Interrupts Signal that causes the CPU to alter its normal flow on instruction execution ◦ frees CPU from waiting for events ◦ provides control for external.
Input and Output Computer Organization and Assembly Language: Module 9.
CHAPTER 9: Input / Output
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
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.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Interrupts and exceptions
Processes and threads.
User-Written Functions
MICROPROCESSOR BASED SYSTEM DESIGN
CS501 Advanced Computer Architecture
Microprocessor and Assembly Language
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Protection of System Resources
Computer Architecture
Interrupts In 8085 and 8086.
CS 3305 System Calls Lecture 7.
CS 286 Computer Organization and Architecture
Microprocessor and Assembly Language
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
CSCI 315 Operating Systems Design
Computer System Overview
Lecture 5: Interrupts in Turbo C++
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
Computer-System Architecture
Module 2: Computer-System Structures
CS 301 Fall 2002 Computer Organization
Processor Fundamentals
MARIE: An Introduction to a Simple Computer
COMPUTER PERIPHERALS AND INTERFACES
Exceptions Control Flow
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Computer Architecture and Assembly Language
Interrupts and Exception Handling
Module 2: Computer-System Structures
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer System Overview
Lecture 6: Structure and Class
Lecture 7 System architecture Input-output
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Module 2: Computer-System Structures
Lecture 12 Input/Output (programmer view)
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:

The slides must be understood in Lecture 5 pages 4, 6, 8,9,12,17,18,19,20,21,22,23,24,25. Some slides have errors. Please use the new one I distributed today. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt Interrupt is a mechanism for diverting the attention of a processor when a particular event occurs, such as I/O device requests. Interrupts cause a break in the normal execution of a program. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Steps taken to process Interrupt 1. On receipt of the interrupt, the processor after executing the current instruction, branches to an interrupt processing routine. The routine is commonly known as Interrupt Handler. 2. The Interrupt Handler will save the current processor data (registers, status register, PC) and determine which device has interrupt the processor (polling). 3. Execution then branches to the so called Interrupt Service Routine associated with the device (causing the interrupt) and the processor executes data transfer. 4. The interrupt system is enable so that further interrupts may be recognized. 5. Return to that program the execution of which was suspended after recognizing the interrupt. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt Vectors the segmented addresses that specify the locations of interrupt handlers are called interrupt “vectors” an interrupt handler is a function/subroutine that takes care of the interrupt. There are 256 interrupt vectors stored in interrupt vector table located at the beginning of the memory some are reserved and some can be used by users 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Types of Interrupt • Hardware Interrupts • CPU Interrupts • Software Interrupts 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Software Interrupts Software interrupts are generated by using the software interrupt instruction. In turbo C: #include <dos.h> geninterrupt(n); BIOS interrupts: provides the most direct, low level interaction with the I/O devices and give a device-independent interface which hides all the details of the hardware architecture from programmers and includes interrupt numbers: 0x05, 0x10-0x1C, 0x48. DOS interrupts: are parts and the DOS operating system, handle file and memory management and executive services: 0x20-0x60 General use interrupts: can be written by users for their own service routines: 0x61-0x67 Notice: no need to remember all the interrupt vectors. Focus on how to invoke an interrupt given the interrupt number and the service number 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie BIOS Keyboard Services They are invoked with interrupt number 0x16 with the following Service numbers in the register AH (_AH in Turbo C). service# functionality 0x00 Read Next Keyboard Character 0x01 Report Whether Character Ready 0x02 Get Shift Status 0x03 Set Typematic Rate and Delay 0x05 Keyboard Write 0x10 Extended Keyboard Read 0x11 Get Extended Keystroke Status 0x12 Get Extended Shift Status Notice: 1. Service numbers are parameters pass to the subroutines/interrupt handlers 2. Try to remember the meaning of service 0x00 and 0x01 for interrupt 0x16. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt 0x16 Service 0x00 Service 0x00 reports the next keyboard input character. If there is no character in the BIOS keyboard buffer, it waits until one is ready. The character is removed from the BIOS keyboard buffer after it is read. The auxiliary byte returned in AH is either the character ID for special characters or the standard PC-keyboard scan code identifying the pressed key. Each character is reported as a pair of bytes. The main byte returned in AL is either 0 for special characters, or an ASCII code for ASCII characters. To invoke this service to read a character into a variable x in Turbo C, we do: char x; _AH=0x0; geninterrupt(0x16); x=_AL; 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie The Steps to Invoke an Interrupt (1) send the service number to _AH; _AH=0x01; (2) invoke the interrupt by using geninterrupt(interrupt number); (3) immediate store the result (if any). Usually the result is in _AL; (int x; x=_AL); (Also somethimes, when input is required, _AL is used to store the input.) See examples later. (If more outputs/inputs are required, other registors like, B or C are used.) We have to referee to book for details. No need to remember ALL. However, the examples given in lectures should be remembered. Remember to include dos.h in your file. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie An Example of Getting a Key from Keyboard char x; int y; _AH=0x0; geninterrupt(0x16); x=_AL; cout <<“The key is: ”<< x <<endl; declare x to be “char” type choose service 0x0 with _AH invoke interrupt 0x16 get ASCII code of key from _AL print the key out Remember to include dos.h in your file. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie A Function to get a key char get_key_number () { //return type of the function is char char a; _AH=0x00; //service number 0x00 geninterrupt(0x16); //interrupt 0x16 a=_AL; //_AL is the key return a; //return the value } Demo the program A:key.cpp in the lecture. 1. Show the program 2. Run the program 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Interrupt 0x16 Service 0x01 Service 0x01 tests whether a keyboard input character is ready. The zero flag (ZF) is used as the signal: 1 indicates no input is ready, 0 indicates a character is ready. In the latter case, the character is not removed from the BIOS keyboard buffer until it is read by service 0x00. To invoke this service in Turbo C, we do: char x; _AH=0x01; geninterrupt(0x16); To test whether a character is ready after the above steps in Turbo C, we do: int y; y=_FLAGS&0x40 if (y==0) … to check whether ZF is 0 or 1. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Use Keyboard BIOS to Read To write a program to read a char from BIOS keyboard buffer, one may first use service 0x01 interrupt 0x16 to test whether there is a key stored in the BIOS buffer, then use service 0x00 interrupt 0x16 to read it. int ch, temp; _AH=0x01; geninterrupt(0x16); temp=_FLAGS&0x40; /*must put the data to temp, see slide 32 */ if (temp==0) { _AH=0; ch=_AL; } The difference is that the computer does not have to wait for users to type it. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Caution when using Pseudo-Variables Pseudo-variables refer to CPU registers which are used by other programs which may run at the same time. One must assign values right before using them and read values right after obtaining them, especially when we program in C. Be careful about the following: A pseudo-variable has no address The values one place in pseudo-variables may NOT be preserved for any length of time. Values of pseudo-variables may not remain the same across a function call. Do not change values of _CS, _SS, _SP, nor _BP since they are used by machine code produced by Turbo C compiler. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Write a function to get a character int key_ready() {//return 1 if a key is ready, 0 otherwise long int x; _AH=1; //service number 0x01 geninterrupt(0x16); //interrupt 0x16 x=_FLAGS &0x40; //get flag register if (x==0) {return 1;} //if x==0 a key is ready else return 0; //else no key } char read_a_key() { //return char if a key is ready if (key_ready()) {return get_key_number().x;} else return 0; 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie The following does not work int key_ready() {//return 1 if a key is ready, 0 otherwise long int x; _AH=1; //service number 0x01 geninterrupt(0x16); //interrupt 0x16 if (_FLAGS&0x40==0) {return 1;} else return 0; //else no key } if (_FLAGS&0x40==0) {return 1;} must be replaced by x=_ FLAGS&0x40; if(x==0) {return 1}; 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Shoot a bullet when press a key #include<dos.h> #include <graphics.h> #include<iostream.h> #include<conio.h> void show(int i,float h, float v); void erease(int i, float h, float v); void main(void) { int driver = DETECT,mode; int i,j,i1,s1; int y=1; initgraph(&driver,&mode,"D:\\bc31\\bgi"); setcolor(WHITE); line(1,400,400,400); for ( i = 0; i < 80; i++ ) show(i, 5.0, 9.0); y=1; _AH=0x01; geninterrupt(0x16);// y=_FLAGS&0x40; if(y == 0) {s1=1;i1=i; _AH=0x00; geninterrupt(0x16);} if (s1==1) {show(i-i1, 10.0, 8.0); } delay (300); erease(i, 5.0, 9.0); if (s1==1) erease(i-i1, 10.0, 8.0); } closegraph(); void show(int i, float h, float v) { int x, y; x=h*i; y=v*i-0.15*i*i; setcolor(RED); circle(400-x,400-y,2); void erease(int i, float h, float v) { int x, y; setcolor(BLACK); 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie

CS3369 Real Time Control Software/DENG Xiaotie Shoot a bullet when press a key The previously program shows one bullet when you execute the program. If you press ANY key during the execution, the second bullet will start. The starting time is controlled by keys. 11/11/2018 CS3369 Real Time Control Software/DENG Xiaotie