Int 21H [2.0] Function 4CH (76) Terminate process with return code

Terminates the current process, passing a return code to the parent process. This is one of several methods that a program can use to perform a final exit. MS-DOS then takes the following actions:

All memory belonging to the process is released.

File buffers are flushed and any open handles for files or devices owned by the process are closed.

The termination handler vector (Int 22H) is restored from PSP:000AH.

The Ctrl-C handler vector (Int 23H) is restored from PSP:000EH.

[2.0+] The critical-error handler vector (Int 24H) is restored from PSP:0012H.

Control is transferred to the termination handler.

If the program is returning to COMMAND.COM, control transfers to the resident portion and the transient portion is reloaded if necessary. If a batch file is in progress, the next line of the file is fetched and interpreted; otherwise, a prompt is issued for the next user command.

Call with:

AH = 4CH

AL = return code

Returns:

Nothing

Notes:

[2.0+] This is the preferred method of termination for application programs because it allows a return code to be passed to the parent program and does not rely on the contents of any segment register. Other methods of performing a final exit are:

Int 20H

Int 21H Function 00H

Int 21H Function 31H

Int 27H

Any files that have been opened using FCBs and modified by the program should be closed before program termination; otherwise, data may be lost.

The return code can be retrieved by the parent process with Int 21H Function 4DH (Get Return Code). It can also be tested in a batch file with an IF ERRORLEVEL statement. By convention, a return code of zero indicates successful execution, and a non-zero return code indicates an error.

[3.0+] If the program is running on a network, it should remove all locks it has placed on file regions before terminating.

Example:

Terminate the current process, passing a return code of 1 to the parent process.

.

.

.

mov ah,4ch ; function number

mov al,01h ; return code

int 21h ; transfer to MS-DOS