DOS Interrupts 

The interrupt types 20h-3Fh are serviced by DOS routines that provide high-level service to hardware as well as system resources such as files and directories. The most useful is INT 21H, which provides many functions for doing keyboard, video, and file operations.

Interrupt 20h -- Program Terminate

Interrupt 20h can be used by a program to return control to DOS. But because CS must be set to the program segment prefix before using INT 20h, it is more convenient to exit a program with INT 21H, function 4Ch.

Interrupt 21h -- Function Request

This routine provides over 80 functions that maybe classified as character I/O, file access, memory management, disk access, networking, and miscellaneous. The following table summarizes some of these functions:

FunctionDescription
0h: Program TerminateTerminates the execution of a program
1h: Keyboard Input with EchoRead a character from the keyboard into AL with echo
2h: Display OutputDisplay the character in DL to the screen
5h: Printer OutputOutputs the character in DL to the printer
8h: Keyboard Input without EchoRead a character from the keyboard into AL without echo
9h: Print StringDisplay the string characters addressed by DX to the screen
0Ah: Read StringRead a string from the keyboard into buffer addressed by DX
25h: Set VectorSets the address of an interrupt number in the IVT
2Ah: Get DateReturns the day of the week, year, month and date
2Bh: Set DateSets the date
2Ch: Get TimeReturns the time: hours, minutes, seconds, and hundredths
2Dh: Set TimeSets the time
35h: Get VectorObtains the address of an interrupt number from the IVT
39h: Create Subdirectory (MKDIR)Creates the specified directory.
3Ah: Remove Subdirectory (RMDIR)Removes the specified directory.
3Bh: Change the Current Directory (CHDIR)Changes the current directory to the specified directory.
3Ch: Create a FileCreates a new file
3Dh: Open a FileOpens a file
3Eh: Close a File HandleCloses the specified file handle
3Fh: Read from a FileTransfers the specified number of bytes from a file to a buffer
40h: Write to a FileTransfers the specified number of bytes from a buffer into a file
41h: Delete a File from a Specified DirectoryRemoves a directory entry associated with a file name
47h: Get Current DirectoryPlaces the full path name of the current directory in the area pointed by DS:SI.
48h: Allocate MemoryAllocates the requested number of paragraphs of memory
49h: Free Allocated MemoryFrees the specified allocated memory
4Ch: Terminate a Process (EXIT)Terminates the current process and transfers control to the invoking process.

Next, we briefly describe some of the DOS INT 21h functions.

Function 0BH -- Check keyboard buffer 
Input: 	AH = 0BH
Output:AL = 00H -- if the keyboard buffer is empty
	AL = FFH -- if the keyboard buffer is not empty

Function 0CH -- Clear keyboard buffer 
Input: 	AH = 0BH
	AL = 01H, 06H, 07H, 08H, or 0AH
Output:It clears the keyboard buffer and performs appropriate 
	function depending on AL content

Function 05H -- Print a character
Input: 	AH = 05H
	DL = ASCII code of the character to be printed
Output:none

Function 2AH -- Get Date
Input: 	AH = 2AH
Output:AL = Day of the week (0=SUN, 6=SAT)
	CX = Year (1980-2099)
	DH = Month (1-12)
	DL = Day (1-31)

Function 2BH -- Set Date
Input: 	AH = 2BH
 	CX = Year (1980-2099)
	DH = Month (1-12)
	DL = Day (1-31)
Output:AL = 00h, if the date is valid
	     FFh, if the date is not valid

Function 2CH -- Get Time
Input: 	AH = 2CH
Output:CH = Hours (0-23)
	CL = Minutes (0-59)
	DH = Seconds (0-59)
	DL = Hundredths (0-99)

 Function 2DH -- Set Time
Input: 	AH = 2DH
	CH = Hours (0-23)
	CL = Minutes (0-59)
	DH = Seconds (0-59)
	DL = Hundredths (0-99)
Output:AL = 00h, if the time is valid
	     FFh, if the time is not valid

Extended Keyboard Keys

The IBM PC keyboard has several keys that are not the ASCII characters. These keys include the function keys, cursor arrows, Home, End, etc. These keys are called extended keys. When an extended key is pressed, the first byte placed in the keyboard buffer is 00H and the second byte is the keyboard scan code for the key.

To read a character from the keyboard using DOS functions, extended keys require two function calls, as shown in the following procedure:

Read the next character code into AL using  INT 21h, function 08h
if (AL<>0) then
	AL = ASCII code (ASCII character)
else
	read the scan code of the extended key into AL using INT 21h, function 07h
	AL = scan code (extended key character)
end if

Interrupt 22h -- 26h

Interrupt routines 22h-26h handle Ctrl-Break, critical errors, and direct disk access.

Interrupt 27h -- Terminate but Stay Resident

Interrupt 27h allows programs to stay in memory after termination.