CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.

Slides:



Advertisements
Similar presentations
Chapter 3 Basic Input/Output
Advertisements

Assembly Language Lecture Presented By Shery khan 10:00 to 11:00
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Chapter 12: Interrupts. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel Microprocessors:
I/O Unit.
Unit 4 Chapter-1 Multitasking. The Task State Segment.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
Interrupt Processing Haibo Wang ECE Department
Introduction to Interrupts
Introduction to Computer Engineering by Richard E. Haskell Interrupts Module M17.3 Sections 11.3, 14.1.
Chapter 11 Interrupt Interface of the 8088 and 8086 Microcomputer
Interrupts – (Chapter 12)
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
MICROPROCESSOR INPUT/OUTPUT
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Lecture 09: Interrupts & The 80x86 IBM PC and Compatible Computers Chapter 14 Interrupts and the 8259 Chip.
Interrupt Interrupt – to break the flow of speech or action of (someone) by saying or doing something (Longman dictionary)
Interrupts Useful in dealing with: The interface: Random processes;
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.
INT- interrupt program execution 1. It decrements the sp by 2 and pushes the flag registers on the stack. 2. Decrement the sp by 2 and push the content.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
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.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
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.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
8086 Interrupts and Interrupt Applications
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 11.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Interrupt-Driven I/O There are different types of interrupts –Hardware Generated by the 8259 PIC – signals the CPU to suspend execution of the current.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
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.
1 Interrupts A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Interrupts and interrupt responses
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Microprocessor Systems Design I
Anton Burtsev February, 2017
Interrupts In 8085 and 8086.
Interrupts – (Chapter 12)
Computer Organization And Assembly Language
Microprocessor and Assembly Language
Subject Name: Microprocessors Subject Code:10EC46 Department: Electronics and Communication Date: /20/2018.
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.
Module 2: Computer-System Structures
11.1 Interrupt Mechanism, Type, and Priority
COMPUTER PERIPHERALS AND INTERFACES
Architectural Support for OS
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
CNET 315 Microprocessor & Assembly Language
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Architectural Support for OS
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Microprocessor and Assembly Language
Presentation transcript:

CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts

Procedures A procedure is a group of instructions that usually performs a particular task. Also called subroutine, method or function. Allows the same piece of code to be reused multiple times. Save memory space. Makes it easier to write program. A procedure begins with the PROC directive and ends with the ENDP directive. Both are preceded by the procedure’s name.

Procedures The directive PROC is followed by the procedure type: NEAR or FAR. NEAR is used for local procedures. Means that the statement that calls the procedure is in the same segment as the procedure itself. NEAR procedure is assumed if the procedure type is not defined. Most procedures are NEAR procedures. FAR is used for global procedures. i.e. the procedure is called by other programs. Means that the calling statement is in different segment. General procedure syntax: NamePROCType ; Body of the procedure RET NameENDP

Procedure Call The instruction used to call a procedure is CALL. Syntax: CALL procedure_name For NEAR procedure call, the CALL instruction will cause: The return address to be saved on the stack. More specifically the offset address of the next instruction, which is contained in the IP register. The IP register to be loaded with the offset address which points to the procedure.

Procedure Return We can return back to the instruction from where the procedure is called by using the RET instruction. There must be at least one RET instruction in the procedure. The RET instruction will cause the return address to be removed from the stack and loaded into the IP register. Will cause the program to leave the procedure and continue executing the instruction after the CALL instruction.

Procedure Call and Return MAIN PROC CALL PROC1 next instruction PROC1 PROC first instruction RET

Procedure Call (Before CALL) MAIN PROC CALL PROC1 next instruction PROC1 PROC first instruction RET Code Segment Offset address IP Stack Segment FE 00FC Offset address SP

Procedure Call (After CALL) MAIN PROC CALL PROC1 next instruction PROC1 PROC first instruction RET Code Segment Offset address IP Stack Segment FE 00FC Offset address SP 0012

Procedure Return (Before RET) MAIN PROC CALL PROC1 next instruction PROC1 PROC first instruction RET Code Segment Offset address IP Stack Segment FE 00FC Offset address SP

Procedure Call (Before CALL) MAIN PROC CALL PROC1 next instruction PROC1 PROC first instruction RET Code Segment Offset address IP Stack Segment FE 00FC Offset address SP 0300

Passing Parameters to Procedure Procedures should be made general enough so that it can operate on any value. Therefore, we need to be able to pass parameters to a procedure. There are three ways to pass parameters to a procedure. Pass through registers Pass through memory Pass through stack

Passing Parameters to Procedure Pass through registers: Parameters are put inside pre-defined registers. The procedure will read the specified registers to get the parameters. Pass through memory: Parameters are put inside pre-defined variables. The procedure will read the specified variables to get the parameters. The variable can be accessed either using its name or using a pointer (a register which contains the offset address of the variable).

Passing Parameters to Procedure Pass through stack: Parameters are pushed into stack before the procedure is called. The procedure will then pop the stack to get the parameters. Need to be aware that the return address is also pushed into the stack. A procedure may also return values to the calling procedure. Can also be achieved by passing through registers or memory.

Passing Parameters to Procedure If a procedure is to be used by other people, it needs to be properly commented to specify how the parameters are passed and returned. When a procedure performs its operation, it may need to use one or more registers. If this is the case, the registers to be used must also be specified in the comments. This will prevent the procedure from overwriting the registers used by the calling procedure.

Passing Parameters to Procedure A procedure can also be designed not to overwrite any register. If any register were to be used inside the procedure, the value of the register must first be pushed into the stack. When the procedure is done using the register, the value is popped back from the stack into the register. From the calling procedure point of view, nothing is changed.

Interrupts An interrupt is an event that causes the CPU to stop executing the current program and execute a procedure to handle the interrupt. The procedure called by an interrupt is called interrupt service routine or interrupt handler. It operates much like a procedure call, but may happen automatically. There three types of interrupts: Hardware interrupt Software interrupt Processor exception

Hardware Interrupt Allows hardware devices to interrupt the operation of the CPU. For example, when a keyboard key is pressed, the CPU must be interrupted to read the key code in the keyboard buffer. The Intel processor has three pins that are related to hardware interrupt: INTR NMI (non-maskable interrupt) INTA

Hardware Interrupt

The general operation of a hardware interrupt goes as follows: The hardware that needs service sends an interrupt request signal to the processor through the INTR pin. The processor acknowledges by sending an interrupt acknowledge signal through the INTA pin. The interrupting device responds by sending an 8- bit interrupt number on the data bus. This interrupt number identifies the interrupt service routine to be executed, as is unique for each device.

Hardware Interrupt The processor suspends the current task it is executing and calls the interrupt service routine. The interrupt service routine services the hardware device and then returns back to the task that the processor was executing. Interrupts can be enabled/disabled using the I bit in the flag register. The instruction STI enables interrupts. The instruction CLI disables interrupts.

Hardware Interrupt The NMI pin is an interrupt input pin which cannot be disabled. An interrupt on this pin will invoke the Type 2 interrupt. This NMI pin is normally used to signal major faults such as: Memory and I/O parity errors, which may indicate bad chips. Power failures

Software Interrupt Software interrupt is used by programs to request system services. It occurs when a program calls an interrupt service routine using the INT instruction. Syntax: INT interrupt_number The processor will treat the software interrupt number the same way as the interrupt number generated by a hardware device.

Processor Exception Exception occurs when a condition arises inside the processor that requires special handling. Example: The divide instruction may cause a divide by zero or a divide overflow error. This will cause an interrupt of Type 0. The processor will then executes the interrupt service routine for interrupt Type 0 to handle this error.

Interrupt Vector Interrupt vector refers to the area in memory which contains the addresses of interrupt service routines. Located in the first 1024 bytes of memory (000000H – 0003FFH) in real mode. In protected mode, the interrupt vector contains the interrupt descriptor table. There are 256 interrupt vectors. Numbered from 0 – 255 (or 0H – FFH). Each interrupt vector contains 4 bytes. The first 2 bytes contain the offset address of the interrupt service routine. The last 2 bytes contain the segment address of the interrupt service routine.

Interrupt Vector To find the interrupt vector for interrupt number n, we just need to multiply n by 4. Example: Interrupt 9 Offset address = 9 x 4 = 36 = 0024H. Segment address = 0024H + 2 = 0026H. Offset of INT 0 Segment of INT 0 Offset of INT 1 Segment of INT 1 Offset of INT FF Segment of INT FF FC 03FF AddressMemory words

Interrupt Vector Intel reserves the first 32 interrupt vectors. Interrupt Type 0 – 31 (or 0H – 1FH). These are where the BIOS interrupts are located. The first five of these are the same in all Intel microprocessors (Interrupt Type 0 – 4). The operating systems may load its interrupt service routine addresses in subsequent interrupt vectors. DOS interrupts can be found in Interrupt Type 20H – 3FH. Other interrupt vectors are available to users.

BIOS Interrupts Interrupt 0H: Divide error Generated after DIV/IDIV instruction if divide overflow or divide by 0 occurs. Interrupt 1H: Single-step / trap Generated after execution of each instruction if the trap flag bit (TF) is set. Interrupt 2H: Non-maskable interrupt Generated when a logic 1 is placed on the NMI input pin.

BIOS Interrupts Interrupt 3H: Breakpoint The only single-byte interrupt instruction. Commonly used to store a breakpoint in a program for debugging. Interrupt 4H: Overflow Generated when the instruction INTO (Interrupt if Overflow) is called and the overflow flag (OF) is set. Interrupt 5H: Print Screen Generated when the Print Screen key is pressed. Also generated when the BOUND instruction is called and the value given is outside the boundary specified.

BIOS Interrupts Interrupt 6H: Undefined Opcode Generated when an invalid instruction is encountered in a program. Interrupt 7H: Coprocessor not available Generated when an attempt is made to execute a floating-point instruction and no numeric coprocessor is not available. Interrupt 8H: Timer Implemented by the system timer circuit. The timer circuit generates Interrupt Type 8 once every 55ms (18.2 times per second).

BIOS Interrupts Interrupt 9H: Keyboard Generated every time a keyboard key is pressed and released. The interrupt service routine will read the scan code and store it in the keyboard buffer. Interrupt 10H: Video Video driver – used by software programs. Interrupt 13H: Disk I/O Disk driver – used by software programs.

BIOS Interrupts Interrupt 14H: Serial port communication Communication driver – used by software programs. Interrupt 16H: Keyboard I/O Keyboard driver – used by software programs. Interrupt 17H: Printer I/O Printer driver – used by software programs. Interrupt 1AH: Real time clock Allows a program to get and set the real-time clock (RTC). Interrupt 1CH: Time tick Called by INT 8 service routine. Users may write own service routine to perform timing operations.

DOS Interrupts Interrupt 20H: Program terminate Allows a program to return control to DOS. However, INT 21H function 4CH is more convenient for this purpose. Interrupt 21H: Function request Provides functions for doing keyboard, video and file operations. Interrupt 27H: Terminate but stay resident Allows a program to stay in memory after termination.

User-defined Interrupt Service Routines There are many situations where it is useful to write our own interrupt service routines. Create new interrupts on the unused interrupt numbers. Replace the default BIOS interrupt service routine. When interrupt occurs, it will perform the operations specified by our interrupt service routine rather than the default BIOS operations. The interrupt service routine itself is just a normal procedure. The only difference is that the last instruction is IRET instead of RET. However, there are extra steps required to make it an interrupt service routine

User-defined Interrupt Service Routines Steps required to set up an interrupt service routine. Save the current interrupt vector. Place the addresses of the user-defined interrupt service routine in the interrupt vector. Restore the previous vector when terminating the program. There are two INT 21H functions that can be used to get and set interrupt vectors.

User-defined Interrupt Service Routines INT 21H, Function 25H Set interrupt vector Input:AH = 25H AL = Interrupt number DS:DX = Address of ISR Output: None INT 21H, Function 35H Get interrupt vector from vector table Input:AH = 35H AL = Interrupt number Output: ES:BX = Address of ISR