INT 21h DOS interrupt


INT 21h / AH=1 – read Character from standard input, with echo, result is stored in AL.

INT  21h
Service no. 01h
Description Example
MOV AH, 1
INT 21h
read Character from standard input, with echo, result is stored in AL.
if there is no Character in the keyboard buffer, the function waits until any key is pressed

INT 21h / AH=2 – write Character to standard output.

INT  21h
Service no. 02h
Description
Example
MOV AH, 2
MOV DH, ‘a’
INT 21h
Write Character to standard output.
entry: DH = Character to write, after executionAL = DH.

INT 21h / AH=5 – output Character to printer.

INT  21h
Service no. 05h
Description Example
MOV AH, 5
MOV DH, ‘a’
INT 21h
output Character to printer. entry: DH = Character to print, after execution AL = DH.

INT 21h / AH=6 – Direct console input or output.

INT  21h
Service no. 06h
Description Example
MOV AH, 6
MOV DH, ‘a’
INT 21h; output Character.
MOV AH, 6
MOV DH, 255
INT 21h; get Character from keyboard buffer (if any) or set ZF=1.
console input or output parameters for output: DH = 0..254 (ascii code)
parameters for input: DH = 255for output returns: AL = DH
for input returns: ZF set if no Character available and AL = 00hZF Clear if Character available.
AL = Character read; buffer is Cleared.

INT 21h / AH=7 – Character input without echo to AL.
if there is no Character in the keyboard buffer, the function waits until any key is pressed.

INT  21h
Service no. 07h
Description Example
MOV AH, 7
INT 21h
Character input without echo to AL.

INT 21h / AH=9 – output of a string at DS:DX. String must be terminated by ‘$‘.

INT  21h
Service no. 09h
Description Example
org 100h
MOV DX, offset msg
MOV AH, 9
INT 21h
RET
msg db “hello world $”
output of a string at DS:DX output of a string at DS:DX. String must be terminated by ‘$‘.

INT 21h / AH=0Ah – input of a string to DS:DX,.

INT  21h
Service no. 0Ah
Description Example
org 100h
MOV DX, offset buffer
MOV AH, 0ah
INT 21h
JMP print
buffer db 10,?, 10 dup(‘ ‘)
print:
xor BX, BX
MOV BL, buffer[1]
MOV buffer[BX+2], ‘$’
MOV DX, offset buffer + 2
MOV AH, 9
INT 21h
RET
input of a string toDS:DX First byte is buffer Size, second byte is number of Chars actually read. this function does not add ‘$’ in the end of string. to print using INT 21h / AH=9 you must set dollar Character at the end of it and start printing from address DS:DX + 2
The function does not Allow to enter more Characters than the Specified buffer Size.

INT 21h / AH=0Bh – get input status;

INT  21h
Service no. 0Bh
Description Example
get input status returns: AL = 00h if no Character available, AL = 0FFh if Character is available.

INT 21h / AH=0CH – flush keyboard buffer and read standard input.

INT  21h
Service no. 0CH
Description Example
Flush keyboard buffer and read standard input entry: AL = number of input function to execute after flushing buffer (can be 01h,06h,07h,08h, or 0Ah – for other values the buffer is flushed but no input is attempted); other registers as appropriate for the selected input function.

INT 21h / AH= 0Eh – select default drive.

INT  21h
Service no. 0Eh
Description Example
Select default drive. Entry: DH = new default drive (0=A:, 1=B:, etc)
Return: AL = number of potentially valid drive letters
Notes: the return value is the highest drive present.

INT 21h / AH= 19h – get current default drive.

INT  21h
Service no. 19h
Description Example
Get current default drive. Return: AL = drive (0=A:, 1=B:, etc)

INT 21h / AH=25h – set interrupt vector;

INT  21h
Service no. 25h
Description Example
Set interrupt vector; input: AL = interrupt number. DS:DX -> new interrupt handler.

INT 21h / AH=2Ah – get system date;

INT  21h
Service no. 2Ah
Description Example
get system date; Return: CX = year (1980-2099). DH = month. DH = day. AL = day of week (00h=Sunday)

INT 21h / AH=2CH – get system time;

INT  21h
Service no. 2CH
Description Example
get system time; Return: CH = hour. CL = minute. DH = second. DH = 1/100 seconds.

INT 21h / AH=35h – get interrupt vector;

INT  21h
Service no. 35h
Description Example
Get interrupt vector; entry: AL = interrupt number;
return: ES:BX -> current interrupt handler.

INT 21h / AH= 39h – make Directory.

INT  21h
Service no. 39h
Description Example
org 100h
MOV DX, offset file_path
MOV AH, 39h
INT 21h
RET
file_path DB “C:\myDIr”, 0   ; path to be created.
end
Make Directory. entry: DS:DX -> ASCII pathname; zero terminated string:
Return: CF Clear if successful AX destroyed.CF set on error AX = error code.
Note: All Directories in the given path must exist except the last one.

 

INT 21h / AH= 3Ah – remove Directory.

INT  21h
Service no. 3Ah
Description Example
Remove Directory. Entry: DS:DX -> ASCII pathname of Directory to be removed.
Return:
CF
 is Clear if successful, AX destroyed CF is set on error AX = error code.Notes: Directory must be empty (there should be no files inSIde of it).

 

INT 21h / AH= 3Bh – set current Directory.

INT 21h
Service no. 3Bh
Description Example
Notes: even if new Directory name include a drive letter, the default drive is not Changed,
only the current Directory on that drive.
Set current Directory. Entry: DS:DX -> ASCII pathname to become current Directory (Max 64 bytes).
Return:Carry Flag is Clear if successful, AX destroyed.
Carry Flag is set on error AX = error code.

INT 21h / AH= 3CH – create or truncate file.

INT  21h
Service no. 3CH
Description Example
MOV CX, 0; normal – no attributes.
 MOV CX, 1;  read-only.
 MOV CX,2;  hidden.
 MOV CX,4;  system
 MOV CX, 7; hidden, system and read-only!
 MOV CX, 16; archive
DS:DX -> ASCII filename.
note: if Specified file exists it is deleted without a warning.
create or truncate file entry:
CX = file attributes:
returns:
CF Clear if successful, AX = file handle.
CF set on error AX= error code.
example:
org 100h
MOV AH, 3CH
MOV CX, 0
MOV DX, offset filename
MOV AH, 3CH
INT 21h
JC err
MOV handle, AX
JMP k
filename db “myfile.txt”, 0
handle dw ?
err:
; ….
k:
RET

INT 21h / AH= 3Dh – open existing file.

INT  21h
Service no. 3Dh
Description note 1: file pointer is set to start of file.
note 2: file must exist.
example:
org 100h
MOV AL, 2
MOV DX, offset filename
MOV AH, 3dh
INT 21h
JC err
MOV handle, AX
JMP k
filename db “myfile.txt”, 0
handle dw ?
err:; ….
k:
RET
open existing file. Entry:
AL = access and sharing modes:
MOV AL, 0; read
MOV AL, 1; write
MOV AL, 2; read/write
DS:DX -> ASCII filename.
Return:
CF Clear if successful, AX = file handle.
CF set on error AX = error code.

INT 21h / AH= 3Eh – Close file.

INT 21h
Service no. 3Eh
Description Example
Close file. Entry: BX = file handle
Return:
CF Clear if successful, AX destroyed.
CF set on error, AX = error code (06h).

INT 21h / AH= 3Fh – read from file.

INT  21h
Service no. 3Fh
Description  

Note: data is read beginning at current file position, and the file position is updated after a successful read the returned AX may be smaller than the request in CX if a partial read occurred.

read from file. Entry:
BX = file handle.
CX = number of bytes to read.
DS:DX -> buffer for data.
Return:
CF is Clear if successful – AX = number of bytes actually read; 0 if at EOF (end of file) before call.
CF is set on error AX = error code.

INT 21h / AH= 40h – write to file.

INT  21h
Service no. 40h
Description  

note: if CX is zero, no data is written, and the file is truncated or extended to
the current position data is written beginning at the current file position, and
the file position is updated after a successful write the usual cause for AX < CX
on return is a full Disk.

Write to file. Entry:
BX = file handle.
CX = number of bytes to write.
DS:DX -> data to write.
return:
CF Clear if successful; AX = number of bytes actually written.
CF set on error; AX= error code.

INT 21h / AH= 41h – delete file (unlink).

INT  21h
Service no. 41h
Description  

Note: DOS does not erase the files data; it merely becomes
inaccessible because the FAT Chain for the file is Cleared deleting a file which is currently open may lead to filesystem corruption.

Delete file (unlink). Entry:
DS:DX -> ASCII filename (no wildcards, but see notes).
return:
CF Clear if successful, AX destroyed. AL is the drive of deleted file (undocumented).
CF set on error AX = error code.

INT 21h / AH= 42h – SEEK – set current file position.

INT  21h
Service no. 42h
Description Example
org 100h
MOV AH, 3CH
MOV CX, 0
MOV DX, offset filename
MOV AH, 3CH
INT 21h  ; create file…
MOV handle, AX
MOV BX, handle
MOV DX, offset data
MOV CX, data_Size
MOV AH, 40h
INT 21h ; write to file…
MOV AL, 0
MOV BX, handle
MOV CX, 0
MOV DX, 7Cont. in next column
MOV AH, 42h
INT 21h ; seek…
MOV BX, handle
MOV DX, offset buffer
MOV CX, 4
MOV AH, 3fh
INT 21h ; read from file…
MOV BX, handle
MOV AH, 3eh
INT 21h ; Close file…
RET
filename db “myfile.txt”, 0
handle dw ?
data db ” hello files! ”
data_Size=$-offset data
buffer db 4 dup(‘ ‘)
SEEK – set current file position. Entry:
AL = origin of MOVe: 0 – start of file. 1– current file position. 2 – end of file.
BX = file handle.
CX:DX = offset from origin of new file position.
Return:
CF Clear if successful, DX:AX = new file position in bytes from start of file.
CF set on error, AX = error code.

Notes:

for origins 1 and 2, the pointer may be positioned before the start of the file; no error is returned in that case, but subsequent attempts to read or write the file will produce errors. If the new position is beyond the current end of file, the file will be extended by the next write (see AH=40h).

INT 21h / AH= 47h – get current Directory.

INT  21h
Service no. 47h
Description  

Notes:

the returned path does not include a drive and the initial backslash.

Get current Directory. Entry:
DH = drive number (00h = default, 01h = A:, etc)
DS:SI -> 64-byte buffer for ASCII pathname.
Return:
Carry is Clear if successful
Carry is set on error, AX = error code (0Fh)

INT 21h / AH=4CH – return control to the operating system (stop program).

INT  21h
Service no. 4CH
Description Example
MOV AX, 4C00h
INT 21h
Return control to the operating system (stop program).

INT 21h / AH= 56h – rename file / MOVe file.

INT  21h
Service no. 56h
Description  

Note: Allows MOVE between Directory is on same logical drive only; open files should not be renamed!

Rename file / MOV file. Entry:
DS:DX -> ASCII filename of existing file.
ES:DI -> ASCII new filename.
Return:
CF Clear if successful.
CF set on error, AX = error code.

Mouse driver interrupts — INT 33h
INT 33h / AX=0000 – mouse initialization. any previous mouse pointer is hidden.

INT  21h
Service no. 0000h
Description Example

MOV AX, 0
INT 33h

Mouse initialization. any previous mouse pointer is hidden. Returns:
if successful: AX=0FFFFh and BX=number of mouse buttons. if failed: AX=0

INT 33h / AX=0001 – show mouse pointer.

INT  21h
Service no. 0001h
Description Example
MOV AX, 1
INT 33h
Show mouse pointer. Make the mouse pointer visible

INT 33h / AX=0002 – hide visible mouse pointer.

INT  21h
Service no. AX=0002h
Description Example
MOV AX, 2
INT 33h
hide visible mouse pointer. Hides the mouse pointer

INT 33h / AX=0003 – get mouse position and status of its buttons.

INT  21h
Service no. 0003h
Description Example
MOV AX, 3
INT 33h
Get mouse position and status of its buttons. returns:
if left button is down: BX=1
if right button is down: BX=2
if both buttons are down: BX=3
CX = x
DX = y

 

error: Content is protected !!