Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  Function 4BH (decimal 75) lets a parent program load a "child" program
  into memory and execute it. This function can also be used to load
  executable code or data into memory without executing it. In both cases,
  you call function 4BH with DS:DX pointing to an ASCIIZ string with the
  path and filename of the file to be loaded. The register pair ES:BX points
  to a parameter block that contains control information for the load
  operation. AL specifies whether the child program is to be executed after
  it is loaded.

  If AL = 00H, DOS allocates memory for the child program, creates a new
  program segment prefix at the start of the newly allocated memory, loads
  the child program into memory immediately above the PSP, and transfers
  control to it. The parent program regains control only when the child
  program terminates. If AL = 03H, DOS does not allocate memory, create a
  PSP for the child program, or transfer control to the program after it is
  loaded. For these reasons, the AL = 03H variation is normally used to load
  a program overlay. It is also an effective way to load data into memory.

  When AL = 00H, ES:BX points to a block 14 bytes long, which contains the
  information shown in Figure 17-13. When AL = 03H, ES:BX points to a block
  4 bytes long, which contains the information shown in Figure 17-14 on the
  following page.

    Offset           Size
  Hex      Dec       (bytes)  Description
  --------------------------------------------------------------------------
  00H       0        2        Segment address of environment string
  02H       2        4        Segmented pointer to command line
  06H       6        4        Segmented pointer to first default FCB
  0AH      10        4        Segmented pointer to second default FCB
  --------------------------------------------------------------------------

  Figure 17-13.  The information in the EXEC parameter block that is pointed
  to by ES:BX when AL = 00H. DOS builds this information into the PSP of the
  program that is being loaded.

    Offset           Size
  Hex      Dec       (bytes)  Description
  --------------------------------------------------------------------------
  00H      0         2        Segment address where file is to be loaded
  02H      2         2        Relocation factor for program (applies only to
                              EXE-format programs)
  --------------------------------------------------------------------------

  Figure 17-14.  The information in the EXEC parameter block that is pointed
  to by ES:BX when AL = 03H.

  Function 4BH clears the carry flag if it successfully loads a program.
  However, in DOS version 2, this function changes all registers, including
  SS:SP. For this reason, you should save the current SS and SP values in
  the code segment before you call function 4BH.

  If function 4BH fails, it sets the carry flag and returns one of the
  following error codes in AX: 01H (invalid function), 02H (file not found),
  03H (path not found), 05H (access denied), 08H (insufficient memory), 0AH
  (invalid environment block), or 0BH (invalid format).

  When a child program is loaded and executed, it inherits any handles
  opened by the parent program. (The only exception, in DOS versions 3.0 and
  later, is when a handle opened by the parent had the inheritance bit of
  its file-access code set to 1.) Because a child program inherits its
  parent's open handles, the parent program can redirect the standard I/O
  handles and use this technique to influence the operation of the child
  program. For example, a parent program might redirect the standard input
  and output devices to files and then use the DOS SORT filter to sort the
  data in one file and copy it to another.

  More commonly, however, a parent program uses EXEC to execute a copy of
  the DOS command interpreter, COMMAND.COM. The parent program can carry out
  any DOS command by passing the command to COMMAND.COM through the EXEC
  parameter block. You can even get fancy by making COMMAND.COM execute a
  batch file--one that the parent program might well have constructed
  dynamically. This batch file could, in turn, invoke other programs and
  then perform the EXIT command, which would end the execution of the
  command interpreter. At that point, the parent program would be back in
  control. This opens up vast and complicated possibilities.

  --------------------------------------------------------------------------
  NOTE:
    Strangely enough, you can't use function 4BH to load overlays created
    with the DOS LINK program's overlay option: LINK builds all program
    overlays into a single executable file, not into separate files as would
    be needed with function 4BH.
  --------------------------------------------------------------------------

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson