MICROPROCESSOR BASED SYSTEM DESIGN

17
MICROPROCESSOR BASED MICROPROCESSOR BASED SYSTEM DESIGN SYSTEM DESIGN BY BY PROF. DR. B. S. CHOWDHRY PROF. DR. B. S. CHOWDHRY Lecture # 19 - Lecture # 19 - 20 20

description

MICROPROCESSOR BASED SYSTEM DESIGN. Lecture # 19 - 20. BY PROF. DR. B. S. CHOWDHRY. INTERRUPTS. Interrupts provide a mechanism for changing program environment. - PowerPoint PPT Presentation

Transcript of MICROPROCESSOR BASED SYSTEM DESIGN

Page 1: MICROPROCESSOR BASED  SYSTEM DESIGN

MICROPROCESSOR BASED MICROPROCESSOR BASED SYSTEM DESIGNSYSTEM DESIGN

BYBY

PROF. DR. B. S. PROF. DR. B. S. CHOWDHRYCHOWDHRY

Lecture # 19 - Lecture # 19 - 20 20

Page 2: MICROPROCESSOR BASED  SYSTEM DESIGN
Page 3: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS INTERRUPTS Interrupts provide a mechanism for changing program Interrupts provide a mechanism for changing program

environment.environment. Transfer of program control is initiated by either the Transfer of program control is initiated by either the

occurrence of an event internal to the microprocessor occurrence of an event internal to the microprocessor or an event in its external hardware.or an event in its external hardware.

For instance, when an interrupt signal occurs indicating For instance, when an interrupt signal occurs indicating that an external device, such as printer, requires that an external device, such as printer, requires service, the microprocessor must suspend what it is service, the microprocessor must suspend what it is doing in the main part of the program and pass control doing in the main part of the program and pass control to a special routine (Interrupt service routine) that to a special routine (Interrupt service routine) that performs the function required by the device.performs the function required by the device.

When microprocessor terminates execution in the main When microprocessor terminates execution in the main program, it remembers the location where it left off program, it remembers the location where it left off and then it picks up execution with the first instruction and then it picks up execution with the first instruction in service routine. After this routine run to completion, in service routine. After this routine run to completion, program control is returned to the point where the program control is returned to the point where the microprocessor originally left the main body of microprocessor originally left the main body of program.program.

Interrupts are particularly useful when interfacing I/O Interrupts are particularly useful when interfacing I/O devices that provide data at relatively low data transfer devices that provide data at relatively low data transfer rates.rates.

Page 4: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS (Contt..)INTERRUPTS (Contt..) Example:Example:

• If the person using the keyboard typed one character If the person using the keyboard typed one character per second, the software for 8255 PPI waits on entire per second, the software for 8255 PPI waits on entire second between each keystroke for the person to type second between each keystroke for the person to type another key. This process is such a tremendous waste another key. This process is such a tremendous waste of time that designers have developed another of time that designers have developed another process called process called Interrupts ProcessingInterrupts Processing to handle this to handle this situation. Interrupts processing allows the situation. Interrupts processing allows the microprocessor to execute other software while the microprocessor to execute other software while the keyboard operator is thinking about what key to type keyboard operator is thinking about what key to type next. As soon as key is pressed, the keyboard encodes next. As soon as key is pressed, the keyboard encodes de-bounced switch and puts out one pulse that de-bounced switch and puts out one pulse that interrupts the microprocessor.interrupts the microprocessor.

• In this way, microprocessor executes other software In this way, microprocessor executes other software until the key is actually passed when it reads a key until the key is actually passed when it reads a key and returns to the program that was interrupted. As a and returns to the program that was interrupted. As a result, the microprocessor can print reports or result, the microprocessor can print reports or complete any other task while the operator is typing a complete any other task while the operator is typing a document and thinking about what to type next.document and thinking about what to type next.

Page 5: MICROPROCESSOR BASED  SYSTEM DESIGN

Figure 1 shows a time line that indicates a typist typing Figure 1 shows a time line that indicates a typist typing data on a keyboard, a printer removing data from data on a keyboard, a printer removing data from memory, and program executing. The program is the memory, and program executing. The program is the main program that is interrupted for each keystroke main program that is interrupted for each keystroke and each character that is to print on the printer.and each character that is to print on the printer.

Note that the keyboard interrupt service procedure, Note that the keyboard interrupt service procedure, called by the keyboard interrupt, and the printer called by the keyboard interrupt, and the printer interrupt service procedure each take little time to interrupt service procedure each take little time to execute.execute.

The 8086/8088 micro-computer are capable of The 8086/8088 micro-computer are capable of implementing any combination of upto 256 implementing any combination of upto 256 INTERRUPTS.INTERRUPTS.

Page 6: MICROPROCESSOR BASED  SYSTEM DESIGN

They are divited into four groups:They are divited into four groups:External Hardware InterruptsExternal Hardware InterruptsSoftware InterruptsSoftware Interrupts Internal InterruptsInternal InterruptsNon maskable Interrupts Non maskable Interrupts

The interrupts of the entire Intel family of The interrupts of the entire Intel family of microprocessors include:microprocessors include:

Hardware pins that request interrupt (INTR & NMI) Hardware pins that request interrupt (INTR & NMI) and one hardware pin (INTA) that acknowledges the and one hardware pin (INTA) that acknowledges the interrupt requested through INTA.interrupt requested through INTA.

In addition to the pins, the microprocessor also has In addition to the pins, the microprocessor also has software interrupts INT, INTO, INT3, and BOUND.software interrupts INT, INTO, INT3, and BOUND.

Two flag bits, IF (Interrupt Flag) and TF (Trap Flag), Two flag bits, IF (Interrupt Flag) and TF (Trap Flag), are also used with the interrupt structure and a are also used with the interrupt structure and a special return instruction IRET (or IRETD in special return instruction IRET (or IRETD in 80386/higher).80386/higher).

Hardware, software, and internal interrupts are Hardware, software, and internal interrupts are serviced on serviced on priority basis.priority basis.

Page 7: MICROPROCESSOR BASED  SYSTEM DESIGN

Internal interrupts are the highest Internal interrupts are the highest priority group.priority group.

Next lowest is the non-maskable Next lowest is the non-maskable interrupt.interrupt.

Next lowest is the software interrupts.Next lowest is the software interrupts.

External hardware interrupts are the External hardware interrupts are the lowest priority group.lowest priority group.

Even within a group, various interrupts Even within a group, various interrupts are given different priority levels. are given different priority levels. (Type (Type 0 identifies the highest priority internal 0 identifies the highest priority internal interrupt and Type 225 identifies interrupt and Type 225 identifies lowest priority internal interrupt).lowest priority internal interrupt).

Page 8: MICROPROCESSOR BASED  SYSTEM DESIGN
Page 9: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORSINTERRUPTS VECTORS The interrupt vectors and vector table are The interrupt vectors and vector table are

crucial to an understanding of hardware crucial to an understanding of hardware and software interrupts.and software interrupts.

The The Interrupt vector tableInterrupt vector table is located in the is located in the first 1,024 bytes of memory at addresses first 1,024 bytes of memory at addresses 000000H – 0003FFH. 000000H – 0003FFH.

It contains 256 different four-byte It contains 256 different four-byte interrupts vectors.interrupts vectors.

An interrupt vector contains the address An interrupt vector contains the address (Segment and offset) of the interrupt (Segment and offset) of the interrupt service procedure.service procedure.

Figure 2 illustrates the interrupt vector Figure 2 illustrates the interrupt vector table for the microprocessor.table for the microprocessor.

Page 10: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORS (Contt..)INTERRUPTS VECTORS (Contt..)

Intel reserves the first 32 interrupt Intel reserves the first 32 interrupt vectors for their use in various vectors for their use in various microprocessor family members.microprocessor family members.

The last 224 vectors are available as The last 224 vectors are available as user interrupt vectors. user interrupt vectors.

Each vector is 4 bytes in length and Each vector is 4 bytes in length and contains the starting address of the contains the starting address of the interrupt service procedure. interrupt service procedure.

The first two bytes of the vector The first two bytes of the vector contain the offset address and the contain the offset address and the last two bytes contain the segment last two bytes contain the segment address.address.

Page 11: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORS (Contt..)INTERRUPTS VECTORS (Contt..) The following list describes the function of The following list describes the function of

each dedicated interrupt in the each dedicated interrupt in the microprocessor:microprocessor:

Type O-Divide Error: Occurs whenever the Type O-Divide Error: Occurs whenever the result of a division overflows or whenever an result of a division overflows or whenever an attempt is made to divide by zero.attempt is made to divide by zero.

Type 1-Single-Step or Trap: occurs after the Type 1-Single-Step or Trap: occurs after the execution of each instruction if the trap (TF) execution of each instruction if the trap (TF) flag bit is set. Upon accepting this interrupt, flag bit is set. Upon accepting this interrupt, the TF bit is cleared so the interrupt service the TF bit is cleared so the interrupt service procedure executes at full speed. procedure executes at full speed.

Type 2-Nonmaskable Hardware Interrupt: a Type 2-Nonmaskable Hardware Interrupt: a result of placing a logic 1 on the NMI input pin result of placing a logic 1 on the NMI input pin to the microprocessor. This input is non-to the microprocessor. This input is non-maskable which means that it cannot be maskable which means that it cannot be disabled.disabled.

Page 12: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORS (Contt..)INTERRUPTS VECTORS (Contt..) Type 3-One Byte Interrupt: is a special one-byte Type 3-One Byte Interrupt: is a special one-byte

instruction (INT 3) that uses this vector to access its instruction (INT 3) that uses this vector to access its interrupt service procedure. The INT 3 instruction is interrupt service procedure. The INT 3 instruction is often used to store a breakpoint in a program for often used to store a breakpoint in a program for debugging.debugging.

Type 4-Overflow: is a specia1 vector used with the Type 4-Overflow: is a specia1 vector used with the INTO instruction. The INTO instruction interrupts the INTO instruction. The INTO instruction interrupts the program if an overflow condition exists as reflected by program if an overflow condition exists as reflected by the overflow flag (OF).the overflow flag (OF).

Type 5-BOUND: is an instruction that compares a Type 5-BOUND: is an instruction that compares a register with boundaries stored in the memory. If the register with boundaries stored in the memory. If the contents of the register is greater than or equal to the contents of the register is greater than or equal to the first word in memory and less than or equal to the first word in memory and less than or equal to the second word, no interrupt occurs because the second word, no interrupt occurs because the contents of the register is within bounds. If the contents of the register is within bounds. If the contents of the register is out of bounds, a type 5 contents of the register is out of bounds, a type 5 interrupt executes. interrupt executes.

Type 6-lnvalid Opcode: occurs whenever an undefined Type 6-lnvalid Opcode: occurs whenever an undefined opcode is encountered in a program. opcode is encountered in a program.

Page 13: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORS (Contt..)INTERRUPTS VECTORS (Contt..) Type 7-Coprocessor Not Available: occurs when a coprocessor Type 7-Coprocessor Not Available: occurs when a coprocessor

is not found in the system as dictated by the machine status is not found in the system as dictated by the machine status word (MSW) coprocessor control bits. If an ESC or WAIT word (MSW) coprocessor control bits. If an ESC or WAIT instruction executes and the coprocessor is not found, a type 7 instruction executes and the coprocessor is not found, a type 7 exception or interrupt occurs.exception or interrupt occurs.

Type 8-Double Fault: is activated whenever two separate Type 8-Double Fault: is activated whenever two separate interrupts occur during the same instruction.interrupts occur during the same instruction.

Type 9-Coprocessor Segment Overrun: occurs if the ESC Type 9-Coprocessor Segment Overrun: occurs if the ESC instruction (coprocessor opcode) memory operand extends instruction (coprocessor opcode) memory operand extends beyond offset address FFFFH For 286 & Higherbeyond offset address FFFFH For 286 & Higher

Type 10-lnvalid Task State Segment (TSS): occurs if the TSS is Type 10-lnvalid Task State Segment (TSS): occurs if the TSS is invalid because the segment limit field is not 002BH or higher. invalid because the segment limit field is not 002BH or higher. In most cases this is caused because the TSS is not initialized.In most cases this is caused because the TSS is not initialized.

Type 11-Segment not Present: interrupts occur when the P bit Type 11-Segment not Present: interrupts occur when the P bit (P = 0) in a descriptor indicates that the segment is not (P = 0) in a descriptor indicates that the segment is not present or not valid.present or not valid.

Type 12-Stack Segment Overrun: occurs if the stack segment is Type 12-Stack Segment Overrun: occurs if the stack segment is not present (P = 0) or if the limit of the stack segment is not present (P = 0) or if the limit of the stack segment is exceeded.exceeded.

Page 14: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS INSTRUCTIONSINTERRUPTS INSTRUCTIONS

A number of instructions are provided in the A number of instructions are provided in the instruction set of the 8086/8088 microprocessors, instruction set of the 8086/8088 microprocessors, for use with interrupt processing. for use with interrupt processing.

Page 15: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS VECTORS (Contt..)INTERRUPTS VECTORS (Contt..) Type 13-General Protection: occurs for most Type 13-General Protection: occurs for most

protection violation in the 80286/ 80386/80486 protection violation in the 80286/ 80386/80486 protected mode system. A list of these protection protected mode system. A list of these protection violations follows: violations follows:

a.a. descriptor table limit exceededdescriptor table limit exceededb.b. privilege rules violatedprivilege rules violatedc.c. invalid descriptor segment type loadedinvalid descriptor segment type loadedd.d. write to code segment that is protectedwrite to code segment that is protectede.e. read from execute-only code segmentread from execute-only code segmentf.f. write to read-only data segmentwrite to read-only data segmentg.g. segment limit exceededsegment limit exceeded

Type l4-Page Fault: occurs for any page fault Type l4-Page Fault: occurs for any page fault memory or code access in the 80386 and 80486 memory or code access in the 80386 and 80486 microprocessors.microprocessors.

Type l6-Coprocessor Error: takes effect whenever a Type l6-Coprocessor Error: takes effect whenever a coprocessor error coprocessor error ((ERROR= 0) occurs for the ERROR= 0) occurs for the ESCAPE or WAIT instructions for the 80386 ESCAPE or WAIT instructions for the 80386 microprocessor only.microprocessor only.

Page 16: MICROPROCESSOR BASED  SYSTEM DESIGN

INTERRUPTS INSTRUCTIONS (Contt..)INTERRUPTS INSTRUCTIONS (Contt..)

Use of Use of software interrupt software interrupt instruction INT n.instruction INT n.

INT n is used to initiate a software call of INT n is used to initiate a software call of subroutine. Executing the instruction causes subroutine. Executing the instruction causes transfer of program control to the subroutine transfer of program control to the subroutine pointed to by the vector for type number n pointed to by the vector for type number n specified in the instruction.specified in the instruction.

Example:Example:

INT 50 initiates execution of a subroutine whose INT 50 initiates execution of a subroutine whose starting point is identified by vector 50 in the starting point is identified by vector 50 in the pointer table. That is, the microprocessor reads pointer table. That is, the microprocessor reads IP50 and CS50 from address 000 C8IP50 and CS50 from address 000 C81616 and 000CA and 000CA1616, , respectively, in memory, loads these values into IP respectively, in memory, loads these values into IP and CS, calculates the physical address, and starts and CS, calculates the physical address, and starts to fetch instructions from this new location in to fetch instructions from this new location in program memory. program memory.

Page 17: MICROPROCESSOR BASED  SYSTEM DESIGN