Você está na página 1de 18

Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Chapter 4

Interrupts of X86 microprocessor


20 Marks
Syllabus:
Introduction to X86 interrupts (Hardware, software and exceptions), Interrupt vector table, Interrupt
processing sequence. Hardware or exception interrupts (Singles step, divide by zero/overflow, non-
maskable, breakpoint, overflow) software interrupts (INT, INTO instructions)
Introduction to .com and .exe programs, DOS& BIOS Interrupts INT 21H, INT 25H, INT 26H, INT 10H,
INT 16H, INT 17H.

Introduction to X86 interrupts (Hardware, software and exceptions):


Interrupts and exceptions are special kinds of control transfer; they work somewhat like
unprogrammed CALLs. They alter the normal program flow to handle external events or to report errors
or exceptional conditions. The difference between interrupts and exceptions is that interrupts are used to
handle asynchronous events external to the processor, but exceptions handle conditions detected by the
processor itself in the course of executing instructions.

There are two sources for external interrupts and two sources for exceptions:
1. Sources of Interrupts
Maskable interrupts, which are signaled via the INTR pin.
Non-maskable interrupts, which are signaled via the NMI (Non-Maskable Interrupt) pin.
2. Sources of Exceptions
Processor detected. These are further classified as faults, traps, and aborts.
Programmed. The instructions INTO, INT 3, INT n, and BOUND can trigger exceptions. These
instructions are often called "software interrupts", but the processor handles them as exceptions.
Identifying Interrupts
The processor associates an identifying number with each different type of interrupt or exception.

1
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

The NMI and the exceptions recognized by the processor are assigned predetermined identifiers in the
range 0 through 31. Not all of these numbers are currently used by the 80386; unassigned identifiers in
this range are reserved by Intel for possible future expansion.
The identifiers of the maskable interrupts are determined by external interrupt controllers (such as
Intel's 8259A Programmable Interrupt Controller) and communicated to the processor during the
processor's interrupt-acknowledge sequence. The numbers assigned by an 8259A PIC can be specified
by software. Any numbers in the range 32 through 255 can be used.
Following table shows the assignment of interrupt and exception identifiers.
Exceptions are classified as faults, traps, or aborts depending on the way they are reported and
whether restart of the instruction that caused the exception is supported.
Faults: Faults are exceptions that are reported "before" the instruction causing the exception. Faults are
either detected before the instruction begins to execute, or during execution of the instruction. If detected
during the instruction, the fault is reported with the machine restored to a state that permits the
instruction to be restarted.
Traps: A trap is an exception that is reported at the instruction boundary immediately after the
instruction in which the exception was detected.
Aborts: An abort is an exception that permits neither precise location of the instruction causing the
exception nor restart of the program that caused the exception. Aborts are used to report severe errors,
such as hardware errors and inconsistent or illegal values in system tables.
Table Interrupt and Exception ID Assignments:
Identifier Description
0 Divide error
1 Debug exceptions
2 Nonmaskable interrupt
3 Breakpoint (one-byte INT 3 instruction)
4 Overflow (INTO instruction)
5 Bounds check (BOUND instruction)
6 Invalid opcode
7 Coprocessor not available
8 Double fault
9 (reserved)
10 Invalid TSS
11 Segment not present
12 Stack exception
13 General protection
14 Page fault
15 (reserved)

2
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

16 Coprecessor error
17-31 (reserved)
32-255 Available for external interrupts via INTR pin

Enabling and Disabling Interrupts


The processor services interrupts and exceptions only between the end of one instruction and the
beginning of the next. When the repeat prefix is used to repeat a string instruction, interrupts and
exceptions may occur between repetitions. Thus, operations on long strings do not delay interrupt
response.
Certain conditions and flag settings cause the processor to inhibit certain interrupts and exceptions at
instruction boundaries.

Interrupt vector table:

Figure shows the 256 interrupt vectors are arranged in the table in memory. Note that the instruction
pointer value is put in as the low word of the vector, and the code segment register is put in as the high word
of the vector. Each double word interrupt vector is identified by number from 0 to 255. Intel calls this
number the type of interrupt.

3
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

The lowest five types are dedicated to specific interrupts, such as the divide by zero interrupt, the
single step interrupt, and the non maskable interrupt. Interrupts types 5 to 31 are reserved by intel for using
more complex microprocessor, such as the 80286, 80386, and 80486. The upper 224 interrupts types, from
32 to 255, are available for use of hardware and software interrupts,
In the figure the vector for each interrupt types requires four memory location. therefore, when the 8086
represent to a particular type interrupt, it automatically multiplies the type by 4 to produce the desired address
in vector table. It then goes to the address in the table to get the starting address of the interrupt service
procedure.

The structure of MS-DOS:

BIOS:
BIOS is specific to individual computer system and it is provided by the manufacturer of the system. It
contains device driver for the following devices.
1) Keyboard
2) Printer
3) Auxiliary device
4) Date and time
5) Boot disk device
DOS - Kernel:
The Kernel is a proprietary program supplied by Microsoft corporation & provides collection of
hardware independent services on system function such as:
File & Record Management
Memory Management

4
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Character Device I/O


Spawning of other program
Access to the real time clock
Command Processor:
Intrinsic command internal command
Extrinsic command external command
It is the user interface to the operating system. It is responsible for carrying out the commands i.e.
loading or execution of program from the disk or mass storage device.
The default shall command is command.com. It is a program under the control of MS DOS. It is
fetcher divided into:
A resident portion at low portion of memory.
Initialization section at middle portion of the memory.
Transient Module at the high end of the memory.
The user commands are divided into three categories:
1) Internal Commands:
Intrinsic command by command.com e.g. copy, rename, delete etc.
2) External commands:
Extrinsic command e.g. check disk, back up etc.
3) Batch file:
There are the text files containing list of extrinsic & intrinsic commands.

DOS-BIOS interface:

One of task of the operating system is to interface with BIOS when there is a need to access its facilities.
When a user program requests an IO service of the operating system, it transfers the request to BIOS,
which in its turn accesses the requested device. Sometimes, a program makes request directly to bios,
such as for keyboard and screen services. At other times a program can bypass both the operating system
and BIOS to access a device directly. Figure below shows these alternative paths.
5
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Loading of MS-DOS:

When the system is reset or started, the program execution begins at the address 0FFFF0H. The
control is transferred to system test code, power on self-test (POST). Then the control is transferred to
the ROM bootstrap routine, which reads thedisk bootstrap from the first sector of the system startup disk
into memory at some arbitrary address and transfers control to it.
The disk bootstrap checks to see if the boot disk contains DOS by checking the first sector of the root
directory for the file IO.SYS and MSDOS.SYS. If these are not found in the boot disk, the user gets a
prompt for changing the disk. If the two files are found, the disk bootstrap reads the files into memory
and transfers the control to IO.SYS
The IO.SYS file consists of two separate modules. The first is the BIOS, which contains the linked
set of resident device drivers for the console, auxiliary port, printer, clock devices and some hardware
specific initialization code. Second module consists of system initialization program, which determines
the RAM size in the PC. Then it loads the MSDOS.SYS program to its final memory location of the
DOS Kernel program.
The DOS Kernel initializes its tables and sets up its various work areas. It sets up the various
interrupt vectors for the DOS interrupts 20H-2FH pointing them to appropriate service routine. It then

6
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

loads and executes the device drivers. Now it returns the control to system initialization program
(SYSINIT).
The SYSINIT calls MS-DOS file service to open the CONFIG.SYS file. It contains the list of
additional device drivers that the user wants in his system. The required drivers are loaded into the
memory, initialized by calls to their INIT modules, and linked into their device driver list.
After SYSINIT calls the EXEC function to load the command interpreter (shell). Once the interpreter is
loaded, it displays a prompt and waits for the user to enter the command.

Priority of 8086 interrupts:


In 8086 the interrupts are serviced as per the following priority order. Interrupts are listed from highest
to lowest priority order.
Internal interrupts and exceptions
Software interrupts
Non maskable interrupts (NMI)
External hardware interrupts (INTR)

Interrupt processing sequence of 8086

7
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

1) Decrement stack pointer by 2 & push flag register on stack.


2) Clear the interrupt flag.
3) Clear trap flag in flag register.
4) Decrement stack pointer by 2 & store code segment in it.
5) Decrement stack pointer by 2 & pushes IP in it.
6) Fetch the ISR address from IVT & execute it.
After the completion of ISR, it decodes the instruction IRET & retrieves the main program address & status
of flag register.

Difference between .com and .exe programs


.COM program .EXE program
1- In .COM program data, code and Stack reside in .EXE program can have multiple code,data an stack
one segment. segment.

2- The .COM files are compact and are loaded .EXE files contain unique header, a relocation map, a
slightly faster than equivalent .EXE file, since these checksum and other information used by DOS along
contain only the execution code. with the execution code.
3- Near subroutine are used in .COM files. .EXE programs can contain more than one code
segment so both near and far CALLS are used.

4- CS starts at 0000H and IP at 0100H. Not fixed.

5- Maximum length of program ( code and data) is .EXE program can be as large as available memory.
65536 bytes(64 K) minus 256 bytes of PSP.

6- In .COM format the size of the file is exact the In .EXE format the size of the file is size of the
size of the program. program plus the size of the header.

7- .COM program does not require file header. .EXE program need file header for relocation
process.

8
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Difference between DOS and BIOS:


DOS BIOS

1- DOS is loaded from bootable disc. BIOS is located in ROM.

2- DOS is not specific to a computer system. BIOS is specific to a computer system.

Routines of BIOS provide direct, low level


3- DOS programs offer different degree of flexibility,
interaction with various devices in the system. To use
portability and hardware independence.
these routine hardware knowledge is required.
4- DOS has ability to load and execute programs BIOS does not have ability to load and execute
directly. programs directly.
5- DOS can store data on disc organized in the form BIOS cannot store data on disc organized in the form
of logical files. of logical files.
6- DOS has command interpreter which works as
BIOS does not have command interpreter.
interface between operating system and user.

7- DOS is a collection of procedures to perform Its function is to setup hardware, load and start an
services such as formatting disc, portioning disc, operating system
creating, reading, writing files
OR OR

7- The DOS is a proprietary program supplied by It is residual program provided by the manufacturer.
Microsoft corporation & provides collection of Specific BIOS is available for individual computer &
hardware independent services on system function provided by manufacturer. It contains default
such as : resident hardware driver for :
1) File & Record Management 1) Console display & keyboard (CON)
2) Memory Management 2) Line printer (PRN)
3) Character Device I/O 3) Auxiliary Device (AUX)
4) Spawning of other program 4) Date & Time (Clock)
5) Access to the real time clock 5) Boot Disk Device (block device)

8- DOS is user friendly BIOS is complex

9- Speed is slow High

10- For example: INT 21 H For example: Video services INT 10 H etc.

9
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

DOS INT 21H Functions:


Function 01H: Console Input with echo
Reads a single character from the keyboard in AL and displays typed character on screen. If no character
is available, waits until a character is available.
Load AH with 01H,
Call INT 21H,
AL=8 bit ASCII code for the key pressed.
e.g.
MOV AH, 01H
INT 21H
MOV Char, AL ;Char is a variable

Function 02H: Console Output


Writes a single character in DL to the display.
Load AH with 02H,
Load DL with 8 bit ASCII code of the character to be displayed on the screen,.
Call INT 21H.

Function 05H: Printer Output


Writes a single character to the printer
Load AH with 05H,
Load DL with 8 bit ASCII code of the character to be printed,
Call INT 21H.

Function 08H: Read Keyboard without echo


Reads a character from the keyboard in AL. Does not echo the character to the display.
Load AH with 08H,
Call INT 21H,
AL=8 bit ASCII code for the key pressed.

Function 09H: Display String


This function displays the characters from location DS:DX up to (but not including) a terminating $
character.
Load AH with 09H,
Load DS:DX with pointer to string terminated with $,
Call INT 21H.

10
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Function 0AH: Buffered Keyboard Input


This function reads a line of text from the keyboard and stores it into the input buffer pointed at by
DS:DX. The first byte of the buffer must contain a count between one and 255 that contains the
maximum number of allowable characters in the input buffer. This routine stores the actual number of
characters read in the second byte. The actual input characters begin at the third byte of the buffer.
e.g. to read 50 bytes, following code fragment can be used:
.data
Buffer DB 50
DB 0
DB 50 DUP (0)
.code

MOV AH, 0AH
MOV DX, OFFSET buffer
INT 21H

Function 39H: Create Directory


Creates a new directory with the specified name in DS:DX.
Load AH with 39H,
Load DS:DX with pointer to zero terminated pathname,
Call INT 21H.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

Function 3AH: Delete Directory


Deletes the directory with the specified pathname in DS:DX. Error if directory is not empty or the
specified directory is the current directory.
Load AH with 3AH,
Load DS:DX with pointer to zero terminated pathname,
Call INT 21H.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

Function 3BH: Change Directory


Changes the default directory to the specified pathname in DS:DX.
Load AH with 3BH,

11
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Load DS:DX with pointer to zero terminated pathname,


Call INT 21H.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

Function 40H: Write to a File


The write function is used to read some number of bytes from a file. The actual number of bytes is
specified by the CX register. The file handle, which specifies the file to which the bytes are to be written,
is passed in the BX register. The DS:DX register contains the address of a buffer from which the bytes
written to the file are stored.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

Function 41H: Delete a File


This function will delete the specified file from the directory. The filename must be an unambiguous
filename (i.e., it cannot contain any wildcard characters). The DS:DX register contains zero terminated
file path to delete.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

Function 43H: Change/Get File Attributes of a File


This call is useful for setting/resetting and reading a files attribute bits. It can be used to set a file to
read-only, set/clear the archive bit, or otherwise mess around with the file attributes.
AL=00H for GET attribute and AL=00H for SET attribute
CF=0 After success, CH is cleared, CL : Attributes of file
CL: bit 0 : Read only file, bit 1 : Hidden file, bit 2: System file, bit 3 : Volume label, bit 4 : sub-
directory, bit 5: archive file

Function 56H: Rename a File


This command serves two purposes: it allows you to rename one file to another and it allows you to
move a file from one directory to another (as long as the two subdirectories are on the same disk).
AH: 56H
DS:DX : Offset of old file name terminated by 0.
ES:DI : Offset of new file name terminated by 0.
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

12
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

Function 57H: Get/Set File Date and Time


This call sets the last-write date/time for the specified file. The file must be open (using open or
create) before using this function. The date will not be recorded until the file is closed.
AH: 57H
AL: Sub function code
0- Get date and time
1- Set date and time
BX: File handle
CX- Time to be set (if AL=01)
DX- Date to be set (if AL=01)
If AL=0
CX=time in hex format
CX bits : bits 0-4 :seconds in multiple of 2 (0-29)
bits 5-10 : minutes (0-59)
bits 11-15 : hours (0-23)
DX=date in hex format
DX bits : bits 0-4 : day (1-31)
bits 5-8 : month (1-12)
bits 9-15 : year (relative to 1980)
If function is successful Carry Flag (CF) = 0.
If function is not successful Carry Flag (CF) = 1 and AX=Error code.

DOS INT 25H (Absolute Disk Read):


Reads one or more sectors on a specified logical disk.
Load
AL = Drive number (0=A, 1=B, etc)
DS:BX = Disk Transfer Address (buffer)
CX = Number of sectors to read
DX = First relative sector to read
e.g.
MOV AL, 3 ;C drive
LEA BX, Buf
MOV CX, 01
MOV DX, 01
INT 25H
Return: CF set on error
AL = error code

13
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

DOS INT 26H (Absolute Disk Write):


Writes one or more sectors on a specified logical disk.
Load
AL = Drive number (0=A, 1=B, etc)
DS:BX = Disk Transfer Address (buffer)
CX = Number of sectors to write
DX = First relative sector to write
e.g.
MOV AL, 3 ;C drive
LEA BX, Buf
MOV CX, 01
MOV DX, 01
INT 26H
Return: CF set on error
AL = error code

BIOS INT 10H Functions:


Function 06H: Clear or scroll up
If AL contains zero, this function clears the rectangular portion of the screen specified by CL/CH (the
upper left hand corner) and DL/DH (the lower right hand corner). If AL contains any other value, this
service will scroll that rectangular window up the number of lines specified in AL.
Parameters:
AH = 06H
AL = Number of lines to scroll.
BH = Screen attribute for cleared area.
CL = x coordinate upper left hand corner
CH = y coordinate upper left hand corner
DL = x coordinate lower right hand corner
DL = y coordinate lower right hand corner

Function 07H: Clear or scroll down


If AL contains zero, this function clears the rectangular portion of the screen specified by CL/CH (the
upper left hand corner) and DL/DH (the lower right hand corner). If AL contains any other value, this
service will scroll that rectangular window down the number of lines specified in AL.
Parameters:
AH = 07H

14
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

AL = Number of lines to scroll.


BH = Screen attribute for cleared area.
CL = x coordinate upper left hand corner
CH = y coordinate upper left hand corner
DL = x coordinate lower right hand corner
DL = y coordinate lower right hand corner

BIOS INT 16H Functions:


Function 02H: Return Keyboard Shift Key Status
This function returns the state of various keys on the PC keyboard in the AL register.
The values returned are as follows:
Bit Meaning
7 Insert state (toggle by pressing INS key)
6 Caps lock (1 = caps lock on)
5 Num lock (1 = num lock on)
4 Scroll lock (1 = scroll lock on)
3 Alt (1 = Alt key currently down)
2 Ctrl (1 = Ctrl key currently down)
1 Left shift (1 = left shift key down)
0 Right shift (1 = right shift key down)

BIOS INT 17H Functions:


Function 00H: Print a Character
If AH is zero, when you call INT 17h, then the BIOS will print the character in the AL register.
DX = Printer port (0 = LPT1, 1 = LPT2, 2 = LPT3)
After function call, AH= Status of printer
AH Bit Meaning
7 1=Printer busy, 0=printer not busy
6 1=Acknowledge from printer
5 1=Out of paper signal
4 1=Printer selected
3 1=I/O error
2 Not used
1 Not used
0 Time out error

15
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

MSBTE Questions on this chapter

Summer 2015
1. a) Attempt any THREE of the following : 12
(iii) How the interrupt is processed in X86 processor ?
b) Attempt any ONE of the following : 6

2. Attempt any FOUR of the following : 16


e) List the hardware and software interrupts.
f) Describe any two dedicated interrupts.

3. Attempt any FOUR of the following : 16


d) Draw the interrupt vector table of X86 and labelled each field in it.
4. a) Attempt any THREE of the following : 12
(iv) State the functions of following interrupts.
1) INT25H
2) INT10H
3) INT16H
4) INT21H
b) Attempt any ONE of the following : 6

5. Attempt any FOUR of the following : 16


b) State the functions of INT 17H. Give any two examples.
6. Attempt any FOUR of the following : 16
e) State any four difference between .com and .exe program.

Winter 2015
1. a) Attempt any THREE of the following: 12
(iv) Differentiate between .COM and .EXE programs. (any four points)

b) Attempt any ONE of the following: 6


(ii) With the help of neat diagram, describe the interrupt vector table entries.

2. Attempt any TWO of the following: 16


b) List any four file handling functions of INT 21H. Describe the functions with their syntax
and usages.

16
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

3. Attempt any FOUR of the following: 16


e) Write the stepwise procedure, that an interrupt handler must follow while servicing an
interrupt.

4. a) Attempt any THREE of the following: 12


(i) Describe the DOS-BIOS interface with the help of neat diagram.
b) Attempt any ONE of the following: 6

5. Attempt any TWO of the following: 16

6. Attempt any FOUR of the following: 16


e) Describe the structure of MS-DOS with the help of neat diagram.

Summer 2016
1. Attempt any FIVE of the following: 20
g) Describe maskable and non maskable interrupts of X86 processor.

2. Attempt any TWO of the following: 16


c) Explain Dos function 01 H (Keyboard Input with echo) and 02 H (display a character on
screen) of INT21 H with suitable example.

3. Attempt any FOUR of the following: 16


e) Describe Interrupt Vector Table (IVT) of X86 processor with suitable diagram.

4. Attempt any TWO of the following: 16


c) Write interrupt processing sequence of X86 processors in detail.

5. Attempt any FOUR of the following: 16


d) Distinguish between .com and .exe program in DOS. (Any four points)

6. Attempt any TWO of the following: 16


c) Explain any two DOS functions of INT21 H for file processing with suitable example.

Winter 2016
1. Answer any FIVE of the following: 20
e) State the priority interrupts of 80286.
f) Describe any four DOS interrupts.
g) State any four difference between .COM and .EXE program.

2. Attempt any FOUR of the following: 16

17
Computer Department, Jamia Polytechnic (0366) Advanced Microprocessor (AMI 17627)

c) Explain with neat diagram DOS-BIOS interface.

3. Attempt any TWO of the following: 16

4. Attempt any FOUR of the following: 16


d) Which function is used to Delete file? Explain in detail with example.
e) Explain the structure of MS-DOS with respect to its layers.

5. Attempt any FOUR of the following: 16


d) Explain non-maskable interrupts.
6. Attempt any TWO of the following: 16
b) Describe the loading sequence of MS-DOS in memory with neat sketch.

18

Você também pode gostar