Used by programs that need to read and write all possible characters and control codes without any interference from the operating system.
[1] Reads a character from the keyboard or writes a character to the display.
[2.0+] Reads a character from the standard input device or writes a character to the standard output device. I/O may be redirected. (If I/O has been redirected, there is no way to detect EOF or disk full.)
Call with:
AH = 06H
DL = function requested
00H—FEH if output request
0FFH if input request
Returns:
If called with DL = 00H—0FEH
Nothing
If called with DL = FFH and a character is ready
Zero flag = clear
AL = 8-bit input data
If called with DL = FFH and no character is ready
Zero flag = set
Notes:
No special action is taken upon entry of a Ctrl-C when this service is used.
To read extended ASCII codes (such as the special function keys F1 to F10) on the IBM PC and compatibles, you must call this function twice. The first call returns the value 00H to signal the presence of an extended code.
See also Int 21H Functions 01H, 07H, and 08H, which provide character input with various combinations of echo and/or Ctrl-C sensing, and Functions 02H and 09H, which may be used to write characters to the standard output.
[2.0+] You can also read the keyboard by issuing a read (Int 21H Function 3FH) using the predefined handle for the standard input (0000H), if input has not been redirected, or a handle obtained by opening the logical device CON.
[2.0+] You can also send characters to the display by issuing a write (Int 21H Function 40H) using the predefined handle for the standard output (0001H), if output has not been redirected, or a handle obtained by opening the logical device CON.
Examples:
Send the character "*" to the standard output device.
.
.
.
mov ah,6 ; function number
mov dl,'*' ; character to output
int 21h ; transfer to MS-DOS
.
.
.
Read a character from the standard input device and save it in the variable char. If no character is ready, wait until one is available.
char db 0 ; input character
.
.
.
wait: mov ah,6 ; function number
mov dl,0ffh ; parameter for read
int 21h ; transfer to MS-DOS
jz wait ; wait until char ready
mov char,al ; save the character
.
.
.