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:
Function | Description |
|
0h: Program Terminate | Terminates the execution of a program
|
1h: Keyboard Input with Echo | Read a character from the keyboard into AL with echo
|
2h: Display Output | Display the character in DL to the screen
|
5h: Printer Output | Outputs the character in DL to the printer
|
8h: Keyboard Input without Echo | Read a character from the keyboard into AL without echo
|
9h: Print String | Display the string characters addressed by DX to the screen
|
0Ah: Read String | Read a string from the keyboard into buffer addressed by DX
|
25h: Set Vector | Sets the address of an interrupt number in the IVT
|
2Ah: Get Date | Returns the day of the week, year, month and date
|
2Bh: Set Date | Sets the date
|
2Ch: Get Time | Returns the time: hours, minutes, seconds, and hundredths
|
2Dh: Set Time | Sets the time
|
35h: Get Vector | Obtains 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 File | Creates a new file
|
3Dh: Open a File | Opens a file
|
3Eh: Close a File Handle | Closes the specified file handle
|
3Fh: Read from a File | Transfers the specified number of bytes from a file to a buffer
|
40h: Write to a File | Transfers the specified number of bytes from a buffer into a file
|
41h: Delete a File from a Specified Directory | Removes a directory entry associated with a file name
|
47h: Get Current Directory | Places the full path name of the current directory in the area pointed by DS:SI.
|
48h: Allocate Memory | Allocates the requested number of paragraphs of memory
|
49h: Free Allocated Memory | Frees 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.