8086
8086
8086
Gerhard Roehrl
y 1. OVERVIEW The purpose of this manual is two-fold. First, we will provide a brief description of how the 8086/88 microprocessors handle interrupts. Second, we will give an overview of interrupt processing. Finally, we will describe how to use the system service routines in PC/MS-DOS and how to write both Assembly Language and PASCAL programs that make use of PC/MS-DOS system services.
equipment, decides which request has the highest priority and issues an interrupt request to the CPU. Finally, interrupts may be generated as a result of executing the INT instruction. This is referred to as a software interrupt.
28
1C
is invoked if uses create it 3 3 to table of control programs (as with parameters DEBUG) 4 4 to disk base 0010 Generated when arithmetic result overflows 5 5 to high video 0014 Invokes print-screen service routine in graphics characters BIOS 8 8 0020 Generated by hardware clock tick 32 20 0080 Invokes service in DOS 9 all 9 0024 In most models, generated by function-call keyboard action; services in DOS simulated on PCjr for model compatibility 13 D create it, an 0034 Generated during CRT vertical retrace for interrupt routine is video control at program end under DOS 14 E create it, an 0038 Signals diskette attention (e.g. to interrupt routine is 35 23 008C If we invoked 34 22 0088 If we 33 21 0084 Invokes 31 1F 007C 30 1E 0078 Points table Points 000C Used to set break-points in 29 1D 0074 Points video
program-terminate
invoked break
under DOS 15 F create it, an 003C Used in printer control interrupt routine is invoked at critical error under DOS 16 10 absolute 0040 Invokes video display services in diskette read service BIOS 17 11 absolute diskette write service in BIOS in DOS 18 12 program, but it in memoryunder DOS 19 13 to low video 004C Invokes diskette services in BIOS graphics characters; only on PCjr 20 14 program to translate PCjr services in BIOS keyboard into PC keyboard 21 15 0054 to translation for BIOS keyboard-supplement devices Invokes cassette tape services in 73 49 0124 Points table 0050 Invokes communications 72 48 0120 Invokes 68 44 0110 Points 0048 Invokes memory-size service in BIOS 39 27 009C Ends keeps service 0044 Invokes equipment-list 38 26 0098 in DOS Invokes 37 25 0094 Invokes 36 24 0090 If we
22
16
0058
Invokes standard keyboard services in BIOS Invokes printer services in BIOS Activates ROM-BASIC language, or override for it Invokes boot-strap start-up routine in BIOS
23
17
005C
24
18
0060
25
19
0064
Figure 2 The interrupt TYPES reserved for use by the IBM family of personal computers. A comparison of the reserved locations in Figures 1 and 2 show that some of the locations are actually reserved by the processor manufacturer for specified exceptions (e.g., TYPES 0-4).
2.0 PROGRAMMING
Figure 3 presents, in flowchart form, how the 86/88 processors handle internal, nonmaskable (NMI), single step and INTR interrupts. If an INTR interrupt occurs, the CPU checks to see if this kind of interrupt is enabled (through the use of the STI instruction) and if so, acknowledges the interrupt request by generating an interruptacknowledge (IAK) bus cycle. As a result of the IAK bus cycle, the uP reads an 8 bit TYPE number provided by the interrupting device. This TYPE number is used as an index into the interrupt vector table to get the address of the interrupt handler. If Trap Flag (TF) is set, the single step operation is activated. After every instruction, a Type I interrupt is generated and a single step interrupt handler is called. If several interrupts occur simultaneously, the single step function is temporarily disabled during the execution of the INTR vectored interrupt service routine.
procedure. This would allow you to test the NMI procedure without needing to apply an external signal to the processors NMI input line. Software interrupts can also be used to call commonly used procedures from many different programs. The Basic Input/Output System (BIOS) procedures of an IBM computer or compatible are a good example of this use of the INT instruction. The specific functions and use of these procedures will be covered in detail in Section 3, below. Figure 3 The interrupt recognition and processing sequence for the 8086/88 family of processors is shown in flowchart form. In general, INT activates the interrupt procedure specified by the instruction's TYPE operand. To return from an interrupt service routine, the IRET instruction is used. IRET is used to exit any interrupt procedure, whether activated by hardware or software. The specific action of INT and IRET can be found in any reference on the 8086/88 instruction set.
; table content mov ax, word ptr es:[bx+2] ; Load AX with the segment ; address of interrupt type 36 push ax ; store the old interrupt pointer ; table content Now, the interrupt table can be loaded with the new vector locations for the handler you have written. xor ax, ax ; first clear AX mov es, ax ; load ES with the segment address ; for the interrupt pointer table mov bx, 36 ; load BX with interrupt type cli ; disable interrupts during the ; changes to the interrupt table mov word ptr es:[bx], BBBB ; load the lower interrupt pointer ; table word with the base address ; (BBBBH) of the user's interrupt ; service routine mov word ptr es:[bx+2],SSSS ; load the higher interrupt pointer ; table word with the segment address ; (SSSSH) of the user's interrupt ; service routine sti ; re-enable interrupts
Peripheral Devices Services 16 19 20 21 22 10 13 14 15 16 Video-display services Diskette services Communications services Cassette-tape services Standard keyboard services
23
17
Printer services
Figure 4 The twelve BIOS service routines supported by the IBM PC (and compatibles). As a simple example of the use of the BIOS routines, let us assume that we want to set the AT&T PC 6300 monitor to the super high graphic resolution mode 64Ox4OO pixel. Normally the is a tricky programming job if you program the video display controller hardware directly. However, when using the BIOS routines, the control change is extremely simple. mov ah,00h ; load AH with service ; number 0 = "Set video model" mov al,48h ; load AL with mode number ; 48 = "Super high resolution model"
int 10h ; call the BIOS procedure to set ; the desired video mode As a second example we will write some pixels to the screen and create graphics. The code shown below will turn ON one pixel at screen position (0,639): mov ah,OCh ; load number OCh = "write ; pixel dot" mov al,O1h ; set code for pixel color mov dx,0000h ; load DX with row number = 0 mov cx,027Fh ; Load CX with column number = 639d int 10h ; call the BIOS procedure to set ; one pixel on the screen Finally, examine the organization and operation of a program that will send characters to the printer. Note that the BIOS interrupt 17h is used. ; this program initializes the ; printer port and sends a character ; string to the printer code segment ; defines that this is a code segment org 100h ; starting at offset 100h assume cs:code, ds:code ; and assuming the registers CS and ; DS are loaded with the segment ; address for this routine ; for more information, see the ; TURBO-ASSEMBLER manual!
enter proc far; ; this procedure (ENTER) will simply call print ; call the PRINT routine written below ret ; info: see TURBO-ASSEMBLER manual enter endp message db 'Hallo printer, how are you?' db 0dh, 0ah ; a carriage return & line feed is used ; to terminate string messages print proc near mov ah, 01h ; Service number 01 = "Initialize ; printer port" mov dx, 00h ; Use printer port 0 int 17h ; Call procedure to initialize ; printer mov si, offset message ; Load SI with offset of string mov cs,29 ; Load CX with length of string again: mov ah, 00h ; service number 01 = "Print ; character" move al, byte ptr [si] ; Load character to be sent in AL int 17h ; Call procedure to print character cmp ah, 01h ; If character not printed then AH=1 jnz next jmp exit
next: inc si ; Address of next character loop again ; Send next character exit: ret print endp code ends end Note: If you use BIOS Interrupts, make sure, that you save all registers which could be affected by the BIOS routine. Reference [4] provides more details on the operation of the various BIOS routines. 4. SYSTEM CALLS 4.1 Comparing DOS and BIOS Services When you turn on your PC there are several jobs to do. One is to load the operating system from the system disk. If you use MS-DOS (MicroSoft - Disk Operating System), three system files are loaded;IBMBIO.COM, COMMAND.COM and IBMDOS.COM. The file IBMDOS.COM contains DOS service routines. The DOS services, like the BIOS services, can be called by programs through a set of interrupts whose vectors are placed in the interrupt vector table (Section 1.2). The ROM-BIOS routines can be thought of as the lowest-level system software available, performing the most fundamental and primitive input and output operations. The DOS service routines provide more sophisticated and efficient control over the I/O operations than the BIOS routines do, particularly for disk file operations. 4.2 Using DOS interrupts There are nine DOS interrupt services and they are listed in Figure 5. Five of them, interrupts 20h, 25h through 27h and 2fh are "true" DOS interrupt services, each one having a specifically-defined task associated with it.
Interrupt Dec Hex Description
32 come
20
33 34 35 36
21 22 23 24
Function-call umbrella interrupt Terminate address Break address Critical error-handler address Absolute disk read Absolute disk write Terminate-but-stayt
37 38 39 residen 47
25 26 27
2F
Figure 5 The Nine DOS Interrupts. In Section 4.4 we will examine the DOS service routine called by INT 21h. This routine provides under one "umbrella" a set of universal functions we can use in our programs. 4.3 DOS Interrupts Except INT 21h INT 20h "Program Terminate" This interrupt terminates the current process and returns control back to the parent process. For example, if you run a com.file program, INT 20 terminates your program and returns to DOS.
INT 22h, INT 23h, INT 24h
This three interrupts are used to hold segmented addresses. our programs set these addresses to point to special routines. Then, when the appropriate circumstances arise, DOS invokes the routines located at these addresses through these three address interrupts. This interrupts are used for advanced programming. More information about these interrupts are provided in references [1] and [4].
These two interrupts are used to read and write specific disk sectors. They are the only DOS services that ignore the logical structure of a disk and work with individual sectors.
INT 27h "Terminate But Stay Resident"
The Terminate But Stay Resident call is used to establish a section of code as resident in the system after its termination. This system call is often used to install device drivers in memory. 4.4 The Universal Functions of DOS INT 23Lh All of the DOS function calls are invoked by INT 21h. Individual functions are selected in the same way as BIOS functions, placing the function number in the AHRegister. To see how easy the use of DOS functions are, compare the following sample programs with the programs in Section 2.2.
Function "Get Interrupt Vector"
mov ah,35h ; function number in AH-Register mov al,36 ; interrupt type in AL-Register int 21h ; get interrupt vector push bx ; save offset address push es ; save segment address
Function "Set Interrupt Vector
mov dx,xxxx ; offset address in DX-Register mov ds,yyyy ; segment address in DS-Register mov ah,25h ; function number in AH-Register mov al,36 ; interrupt type in AL-Register int 21h ; set interrupt vector
The program "Stopwatch" shows you the use of some other INT 21h functions. More information about these functions is provided in reference [1] and [4].
Range Description DMA controller (8237A-5) 01F Interrupt controller (8259A) 03F Timer (8253-5; 8254.2 in AT) 05F PPI (8255A-5; 8255-5 in PCir) Keyboard (8042) 06F DMA page register (74LS612) 09F NMI (non-maskable interrupt) mask 07F register Interrupt controller 2 (8259A) 0BF Sound generator (SX76496N) DMA controller 2 (8237A-5) 0DF Clear/reset math coprocessor 0F1 Math coprocessor 0FF Joystick (game controller) 207 Expansion unit Parallel printer (secondary) 27F Serial port (primary) 3FF Serial port (secondary) 2FF PCjr n/a PC/XT 000-00F AT 000-
020-027 040-047
020-021 040-043
020040-
060-067 n/a
060-063 n/a
n/a 060-
n/a 0A0-0A7
080-083 0A
080070-
n/a
n/a
0A0-
0C0-0C7 n/a
n/a n/a
n/a 0C0-
n/a n/a
n/a n/a
0F00F8-
200-207
200-20F
200-
n/a n/a
210-217 n/a
n/a 278-
2F8-2FF n/a
3F8-33FF 2F8-2FF
3F82F8-
Prototype card 31F Fixed disk 1F8 Parallel printer (primary) 37F SDLC (secondary bisynchronous 38F communications in AT only) Bisynchronous communications (primary) 3AF Monochrome adapter/printer 3BF Color/graphics adapter 3DF Diskette controller 3F7
n/a
300-31F
300-
n/a n/a
320-32F 378-37F
1F0378-
n/a
380-38F
380-
n/a n/a
n/a 3B0-3BF
3A03B0-
n/a
3D0-3DF
3D0-
0F0-0FF
3F0-3F7
3F0-
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: