There are two kinds of interrupts in the IBM personal computer, the hardware interrupt that is produced by an external device, such as a printer or a disk drive and the software interrupt that is produced by the INT instruction of a program.
If you look at the pinout of the 8088 microprocessor, you will notice that it has a pin marked INTR (pin 18) that is called the interrupt request. When this pin becomes active, the microprocessor is interrupted from what ever it was doing so that it can execute a small interrupt service program to manage the type interrupt request that occurred. One pin for a hardware interrupt is not enough because of the many devices connected to the system bus through the I/O slots and support chips on the mother board.
8259 Interrupt controller chip
The 8259 interrupt controller chip is a very complex programmable IC circuit that manages upto 8 different interrupt inputs on the XT and with two cascaded 8259's upto 15 interrupt inputs on the AT type system board. The 8259 is basically an 8 input priority encoder that has 8 inputs and one output. The output is connected to the INTR pin on the micro-processor and up to 8 devices can be connected to the inputs.If more than one input became active at the exact same time, the input with the lowest number will be processed first, followed by the next and so on. It expands the number of INTERRUPT signals from one to eight with interrupt numbers 0-7.
The following chart shows the priority level of each input and what it is used for.
8259 input # Interrupt # Used for
IRQ0 INT 8 Time of day tick count
IRQ1 INT 9 Keyboard
IRQ2 INT A Color graphic's adapter
IRQ3 INT B Secondary serial adapter
IRQ4 INT C Primary serial adapter
IRQ5 INT D Hard drive (XT)
IRQ6 INT E Floppy drive
IRQ7 INT F Printer
Let's take a look at what happens when you press a key on the keyboard. We'll assume that you are at the DOS prompt and you want to enter the command DIR to do a directory of the active disk drive. While you are looking at the DOS prompt the microprocessor is executing many instruction inside the command.com program. One of the things that must happen is the updating of the time of day. As you know the computer keeps track of the time of day. It does this by counting a number of pulses that the clock generator circuit produces. The time of day is very important, in fact so important it is connected to the IRQ0 pin of the 8259 which has the highest priority of the interrupt controller chip. Every 18 usec the clock circuit will produce an active signal on the IRQ0 line. When this happens the output of the 8259 goes active causing the INTR pin of the micro-processor to go active, interrupting the CPU. The CPU will finish the current instructions it was executing at the time and when finished will begin the process of saving the contents of all of it's registers. To save the contents of the registers, the CPU PUSH'S all of them onto the stack, which is located in the high memory area of RAM. As soon as the CPU is finished preserving it's contents, it will signal the 8259 interrupt controller chip that it is ready to service the request by putting an active signal on the INTA (interrupt acknowledge) line of the control bus. As soon as the INTA signal is produced by the CPU, the 8259 interrupt controller will place a one byte address on the data bus that is used by the CPU to look up the address of a sub-routine program located inside the ROM bios chip that contains all the instructions to update the time of day bytes located in the lower RAM area of memory. After the time of day is up-dated, the CPU must POP the data for the registers back off of the stack. As soon as that is finished and the instruction pointer is pointing back to the program that was running at the time, the program starts to execute it's instructions just as though nothing ever happened.
Block diagram of the 8088 micro-processor circuit. Note the 8259 interrupt controller chip
and it's 8 inputs.
Interrupt vector table
The interrupt vector table is a 1000 byte table of addresses, located at segment:offset 0000:0000 thur 0000:03FF, which is the lowest area of ram. Each entry in this table is a double-word or four bytes long that contains the segment:offset address of the sub-routine for any of 256 possible interrupt service numbers. Each interrupt address is 4 bytes long and it is stored in reverse order. You can calculate the offset into this table for any interrupt number by multiplying the interrupt number times 4. When an interrupt occurs the interrupting device must place a one byte offset on the data bus that will be used to jump to the proper offset for the real address of the interrupt service sub-routine. So, when an interrupt 0 occurs, the number 0 is put on the data bus, and the CPU will jump to offset 0000 to get the address of the interrupt service routine. ( To calculate this, use the equation, Interrupt number X 4. For INT 0 it is 0 X 4 = 0) The following is a print out of the interrupt vector table on my 286 machine. To find the address for INT 10, multiply the interrupt number times 4. ( 10 X 4 = 40 )
The four bytes starting at offset is the double-word address of INT 10 in reverse order.
0000:0040 2D 1B C4 03 These are the bytes at offset 40.
03 C4 1B 2D when you reverse the bytes you will have the segment 03C4:1B2D
offset of the address
0000:0000 8A 10 23 01 F4 06 70 00-16 00 92 06 F4 06 70 00
0000:0010 F4 06 70 00 54 FF 00 F0-A6 EA 00 F0 A6 EA 00 F0
0000:0020 07 01 BC 07 99 01 BC 07-57 00 92 06 6F 00 92 06
0000:0030 87 00 92 06 9F 00 92 06-B7 00 92 06 F4 06 70 00
0000:0040 2D 1B C4 03 4D F8 00 F0-41 F8 00 F0 43 04 BC 07
0000:0050 39 E7 00 F0 FC 01 66 02-2E E8 00 F0 D2 EF 00 F0
0000:0060 00 E0 00 F0 2F 00 07 07-6E FE 00 F0 9F 01 BD 02
0000:0070 53 FF 00 F0 A4 F0 00 F0-22 05 00 00 F0 4C 00 C0
0000:0080 94 10 23 01 9E 10 23 01-6B 05 D1 08 A1 05 D1 08
0000:0090 33 05 D1 08 50 04 BC 07-5C 04 BC 07 BC 10 23 01
0000:00A0 6E 04 BC 07 03 05 BD 02-DA 10 23 01 DA 10 23 01
A software interrupt is executed with an INT instruction in your program. It is similar to the CALL instruction in that, when it is executed the program will jump to another location in memory for the next instruction to be executed and when that group of instructions are finished a RET will return control to the calling program. The INT instructions are located inside IBMBIO and IBMDOS or in some cases inside the ROM bios chip. These instructions are basically sub-routines located inside the operating system.
Where are these sub-routines
The operating system is made up three different programs that are located in low memory starting at 00000 and ending at 0B000. The actual ending address will depend on the version of DOS and the number of device drivers that are loaded during the boot process. The block diagram above shows what the memory map of the IBM PC contains after the boot up.
The first 3FF bytes of RAM, starting at 00000, contain the interrupt vector table, which is a table of addresses that point to the INT xx sub-routines in IBMBIO, IBMDOS or the ROM BIOS chip. (see the discussion on the interrupt vector table)
The next FF bytes starting at 00400 are used by the operating system to store a complete equipment list in HEX form. If this Hex information is properly decoded, it can be used to determine what kind of equipment is connected to the system. Then starting at 00500 is the IBMBIO program that contains all of the sub-routines used by the operating system to interface with the hardware. BIO stands for BASIC INPUT/OUTPUT and it contains very low level instructions that communicate with such devices as the keyboard, printer, video, disk drives and the chips on the mother board.
The next program loaded in is called IBMDOS, which is a little more complex and it contains sub-routines that interface with the DISK OPERATING SYSTEM. The instructions in IBMDOS are communicating with the IBMBIO program and the last program loaded into memory, COMMAND.COM. Command.com is the command interpreter that monitors the keyboard and waits for you to press the enter key. When the enter key is pressed it is command.com's job to determine what command was entered. The command will either be an internal command or an external command, depending on where the instructions for the command are stored. All internal commands are located inside command.com itself and all external commands are located on the disk drive. After the command is interpreted, command.com will pass on all the parameters to the IBMDOS program. IBMDOS will process the parameters into the proper format for the IBMBIO program, which will actually turn on the drive or control the hardware needed for the command entered.
MS-DOS is a three level operating system made up of three programs that are at three levels of programming. Command.com is the highest level because it understands commands like DIR, DATE, COPY etc. IBMDOS is the second highest level because it receives instructions from command.com and passes them on to IBMBIO which is the lowest level of programming. All of the sub-routines that are part of these three programs and written by Micro-soft and IBM, preform specific functions in the computer and it's hardware. For example, there are sub-routines that were written just to control the video monitor and how it displays data on the screen. These routines are used to move the cursor, change the color of the characters that are displayed, change the character size, print strings of text and many other display functions. Other sub-routines control every piece of hardware attached to the system. The sub-routines used in the operating system require many 8088 instructions to preform a specificate task and are very complex in there program style. Fortunately, IBM and Micro-Soft designed a method that allows the computer programmer to utilize all of these tested and proven sub-routines in their own programs. This makes programming a little easier for a programmer because the he/she will spend less time writing code that has already been written by the most knowledgeable programmers in the country. The 8088 was designed with a special instruction called INT that will execute any one of these sub-routines from within our program. INT is what we call a software interrupt, because when it is executed from a program, the micro-processor is interrupted for a time while the sub-routine in IBMBIO or IBMDOS is executed. When the sub-routine is finished the micro-processor can go back to the calling program and finish the remainder of it's
How can we use the interrupts
To use a software interrupt, the programmer must set-up the program before the INT instruction is actually executed. Most interrupts require certain values for the proper operation of the interrupt sub-routine. In other words, all interrupts require an input from your program and it must be stored inside specific registers. The instruction that will actually execute the sub-routine is the INT xx instruction, where xx is a number from 0 - FF, depending on the interrupt you want to execute.
In order to use these interrupts you must make reference to the interrupt list that is
supplied by IBM and Micro-Soft. It is not practical to rewrite this list in this book
because of the size of it's contents. I would recommend that you purchase a book
that contains some of the more common interrupts. This book will, however, list some of the most used interrupts in programming.
The interrupts used in programs are going to access either IBMDOS or IBMBIO and you should know the difference before you use them. In general, any interrupt that calls IBMDOS is going to execute a little slower because, as was stated before, IBMDOS is a higher level program and it's instructions are passed onto IBMBIO which actually turns on the chips. Going thur IBMDOS first, slows down the program but because it is a higher level, the input required from your program is much easier to develop and set-up. DOS interrupts are often referred to as DOS CALLS and they are all INT 2x.
The other interrupt type is often called a BIOS interrupt because it calls sub-routines inside IBMBIO or the ROM BIOS chip. These interrupts are much faster and can speed up a program considerably but, because the BIO is a low level program, the programmer must understand the hardware in the system and supply more input from his program.
The following chart shows the most used interrupts.
BIOS CALLS DOS CALLS
10 | 14 20 | 24
11 | 15 21 | 25
12 | 16 22 | 26
13 | 17 23 | 27
14 | 19 1A |
All of these Interrupts are sub-routines in one of the operating system programs and they are further divided into smaller sub-routines called Functions and Sub-Function. For example, INT 10 has a total of 55 Functions and sub-Functions within it's code. To access a Function within an Interrupt, The calling program must have the Function number inside the AH register.
The AH register is used exclusively for the Function.
Let's write a program that uses an INT instruction, to show how in must be set-up. Our program will put the cursor in the middle of the screen and print the letters CPI. A look through the interrupt list reveals two interrupts that will be needed for this program. INT 10 Function 2 and INT 10 Function 9.
INT 10 Function 2 Set the cursor position
------------------------AH = 02 CURSOR IS MOVED
BH = page number
DH = row (y coordinate)
DL = column (x coordinate)
The x-y coordinate of an 80x25 CGA display is shown below.
INT 10 Function 9 (Write character and
attribute at the cursor
AH = 09 Character displayed
AL = Hex ascii code for character
BH = page number
BL = attribute byte
CX = number of characters to write
B7 B6 B5 B4 B3 B2 B1 B0
| x| R |G |B |x |R |G |B |
back | fore
ground | ground
color | color
The attribute byte is used to set the color of the background and foreground of the characters that are to be displayed. R,G,B are the red, green and blue guns on the Cathode ray tube (CRT). A set bit will turn on the specified gun and produce the desired color. There is a separate RGB bit's for the foreground and background colors.
BITS 0-1-2 control the foreground color.
BITS 4-5-6 control the background color.
BIT 3 controls intensity (1=high)
BIT 7 controls blinking (1=blink)
To produce a blue background and a white foreground
bits 4-2-1-0 will have to be set to a 1.
all other bits are cleared to 0.
The binary number than would be,
0001 0111 binary
1 7 Hex
To do this in a program than BL would have the Hex number 17.
We will begin this program by witting down the necessary steps in the order of execution.
1. Position the cursor to the middle of the
2. Display the letter C.
3. Position the cursor for the next character
4. Display the letter P.
5. Position the cursor for the next character
6. Display the letter I.
This is a simple straight line type program because it is simply going to execute instructions in sequential order starting at offset 0100 in memory. The steps will position the cursor, display the letter. Position the cursor, display the letter etc.
0100 Mov AH,2-------|
0103 Mov DH,C------- | Step 1
0105 Mov DL,24------ | Position the cursor
0107 Mov BH,0-------- | row C, column 24
0109 INT 10
0000 Mov AH,9-------- |
0000 Mov AL,43------- |
0000 Mov BH,0-------- | Step 2
0000 Mov BL,17------- | Display the letter C
0000 Mov CX,1--------- | Blue background
0000 Int 10--------------- White foreground
0000 Mov AH,2--------- |
0000 Mov DH,C-------- | Step 3
0000 Mov DL,25------- |-Position the cursor to
0000 Mov BH,0--------- | row 25, column 25
0000 Int 10 --------------
0000 Mov AH,9----------|
0000 Mov AL,50---------|
0000 Mov BH,0----------| Step 4
0000 Mov BL,17---------| Display the letter P
0000 Mov CX,1----------| Blue background
0000 Int 10---------------- White foreground
0000 Mov AH,2---------|
0000 Mov DH,C----------| Step 5
0000 Mov DL,26---------| Position the cursor to
0000 Mov BH,0----------| row C, column 26
0000 Int 10 -
0000 Mov AH,9-----------|
0000 Mov AL,49----------|
0000 Mov BH,0-----------| Step 6
0000 Mov BL,17----------| Display the letter I
0000 Mov CX,1-----------| Blue background
0000 Int 10----------------- White foreground
0000 Int 20-----------------|End the program
To position the cursor, the program executes an INT_10 Function 2. The values needed in the program are listed below,
AH = 2 For the function number
BH = 0 For the page number (0 is the 1st page
out of 4) in video
DH = C The row number in Hex
DL = 24 The column number in Hex
INT 10 is the instruction that actually makes
the call to IBMBIO.
The same code is used in steps 3 and 5 but the column number in DL is advancing to the next character position.
To display a character, the program executes an INT_10 Function 9. The values needed in the program are listed below,
AH = 9 For the function number
BH = 0 For the page number
AL = 43 The Hex ascii code for the letter C
BL = 17 The attribute byte that will cause
a blue background and a white foreground
CX = 1 For the number of characters to display
The same code is used in steps 4 and 6 but the AL register is different for each letter to be displayed.
This program was written this way to demonstrate how to set-up the registers in your code before the INT instruction is executed. The order that the registers are set-up in the code is not important as long as it is done before the INT. A much more efficient program will be shown later to explain some of the advanced instructions of the 8088.