INT 21h AH=08h waits for a key and returns it in AL without echoing it. Unlike INT 21h AH=07h it treats Ctrl+C the DOS way: ^C is printed and INT 23h executed, which normally ends the program. That suits input the user should not see but that needs no special care, the classic case being a password prompt that prints stars.
MOV SI, OFFSET KEYS1CALL STUFF1 ; "pass" and Enter wait in the BIOS bufferXOR BX, BX ; keys so farNEXT1:MOV AH, 08h ; DOS: read a key, no echoINT 21hCMP AL, 13 ; Enter ends the inputJE DONE1INC BXMOV DL, "*" ; a star instead of the keyMOV AH, 02h ; DOS: print the character in DLINT 21hJMP NEXT1DONE1:MOV DL, " "MOV AH, 02h ; DOS: print the character in DLINT 21hMOV DL, BLADD DL, "0" ; the count as a digitMOV AH, 02h ; DOS: print the character in DLINT 21hMOV DX, OFFSET MSG1MOV AH, 09h ; DOS: print the string at DS:DXINT 21hKEYS1 DW 1970h, 1E61h, 1F73h, 1F73h, 1C0Dh, 0 ; p a s s EnterMSG1 DB " keys", 13, 10, "$"STUFF1 PROC NEAR ; "type" the keys at DS:SI: words, 0 ends the listCLDST1:LODSW ; AH = scan code, AL = ASCIITEST AX, AXJZ ST2MOV CX, AX ; CH = scan code, CL = ASCIIMOV AH, 05h ; BIOS: store a keystroke in the keyboard bufferINT 16hJMP ST1ST2:RETSTUFF1 ENDP
Enter arrives as 0Dh, Backspace as 08h and Esc as 1Bh; with no echo nothing appears on the screen unless the program draws it. A real password prompt would also handle Backspace (remove the last key, print 08h, space, 08h) and stop at the size of its buffer. Special keys come as 00h followed by the scan code on the next call, as with the other key services.
| Service | Waits for a key | Echo | Ctrl+C |
|---|---|---|---|
INT 21h AH=01h | yes | yes | ^C, INT 23h: normally the end of the program |
INT 21h AH=06h (DL = FFh) | no: ZF = 1 when none is waiting | no | returned as 03h |
INT 21h AH=07h | yes | no | returned as 03h |
INT 21h AH=08h | yes | no | ^C, INT 23h |
INT 21h AH=0Ah | for a whole line, up to Enter | yes | ^C, INT 23h |
Pitfalls
Because the call can end the program, do not use it while the program has something to undo: a hooked vector would be left pointing into freed memory, a changed video mode would stay changed. Read with INT 21h AH=07h then, or install an INT 23h handler that cleans up. And like every handle-0 read, it takes its input from the file when the program runs with < FILE.