Int 21H [2.0] Function 4BH (75) Execute program (EXEC)

Allows an application program to run another program, regaining control when it is finished. Can also be used to load overlays, although this use is uncommon.

Call with:

AH = 4BH

AL = subfunction

00H = Load and Execute Program

03H = Load Overlay

ES:BX = segment:offset of parameter block

DS:DX = segment:offset of ASCIIZ program pathname

Returns:

If function successful

Carry flag = clear

[2] all registers except for CS:IP may be destroyed

[3.0+] registers are preserved in the usual fashion

If function unsuccessful

Carry flag = set

AX = error code

Notes:

The parameter block format for Subfunction 00H (Load and Execute Program) is as follows:

Bytes Contents 00H—01H segment pointer to environment block 02H—03H offset of command line tail 04H—05H segment of command line tail 06H—07H offset of first FCB to be copied into new PSP + 5CH 08H—09H segment of first FCB 0AH—0BH offset of second FCB to be copied into new PSP + 6CH 0CH—0DH segment of second FCB

The parameter block format for Subfunction 03H (Load Overlay) is as follows:

Bytes Contents 00H—01H segment address where overlay is to be loaded 02H—03H relocation factor to apply to loaded image

The environment block must be paragraph-aligned. It consists of a sequence of ASCIIZ strings in the form:

db 'COMSPEC=A:\COMMAND.COM',0

The entire set of strings is terminated by an extra null (00H) byte.

The command tail format consists of a count byte, followed by an ASCII string, terminated by a carriage return (which is not included in the count). The first character in the string should be an ASCII space (20H) for compatibility with the command tail passed to programs by COMMAND.COM. For example:

db 6,' *.DAT',0dh

Before a program uses Int 21H Function 4BH to run another program, it must release all memory it is not actually using with a call to Int 21H Function 4AH, passing the segment address of its own PSP and the number of paragraphs to retain.

Ordinarily, all active handles of the parent program are inherited by the child program, although the parent can prevent this in MS-DOS 3.0 and later by setting the inheritance bit when the file or device is opened. Any redirection of the standard input and/or output in the parent process also affects the child process.

The environment block can be used to pass information to the child process. If the environment block pointer in the parameter block is zero, the child program inherits an exact copy of the parent's environment. In any case, the segment address of the child's environment is found at offset 002CH in the child's PSP.

After return from the EXEC function call, the termination type and return code of the child program may be obtained with Int 21H Function 4DH.

Example:

See Chapter 12.