Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- DOS 5.0 Ref. - <b>function 4b00h load and execute program (exec)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function 4B00h          Load and Execute Program (EXEC)

    Loads a program into memory, creates a new program segment prefix
    (PSP), and transfers control to the new program.

        Entry   AX    = 4B00h
                DS:DX = Pointer to ASCIIZ program name (.COM or .EXE)
                ES:BX = Pointer to a LoadExec structure

        Return  Expect all registers to be changed, except CS:IP
                AX = Error code, if CF is set
                     | 01h Invalid function number
                     | 02h File not found
                     | 03h Path not found
                     | 04h No handle available
                     | 05h Access denied
                     | 08h Insufficient memory
                     | 0Ah Invalid environment
                     | 0Bh Invalid format

    ------------------------------------------------------------------

    Before function 4B00h (EXEC) is invoked, DS:DX must point to a
    zero-terminated string that specifies the program to load. The
    program name must be a valid DOS filename, and the file must be a
    valid .COM or .EXE program. ES:BX must point to a LoadExec
    structure containing pointers to data that DOS copies to the child
    program's PSP and environment block.

    There must be enough free memory for DOS to load the program file.
    All open files of the parent program, except files that were
    opened in no-inheritance mode, are available to the newly loaded
    program.

    ------------------------------------------------------------------

    Example

        ideal
        model   small

        STACK   100h
        DATASEG
        include "strucs.inc"            ; Get LoadExec definition
        prog_name db "c:\command.com",0
        cmd_line  db 7," /c DIR",0dh
        exec_args LoadExec \
          <0000h, dgroup:cmd_line, dgroup:dummyFCB, dgroup:dummyFCB>
        saved_stack     dd ?
        dummyFCB        db 11 dup (" "), 5 dup (0)

        CODESEG
    start:
        StartupCode
        assume  es:nothing
        mov     bx,TOP_OF_MEM           ; Must shrink memory before exec
        mov     ax,es                   ; ax = PSP segment
        sub     bx,ax                   ; bx = no. of paragraphs needed
        mov     ah,4ah                  ; Resize memory block (at es)
        int     21h
        jc      exec_failed
        mov     [word low  saved_stack],sp ; Save stack info
        mov     [word high saved_stack],ss
        mov     dx,offset prog_name     ; ds:dx -> program name
        mov     bx,ds
        mov     es,bx
        mov     bx,offset exec_args     ; es:bx -> parameter block
        mov     ax,4b00h                ; Load and Execute Program
        int     21h
        assume  nothing,cs:@code
        mov     ax,dgroup               ; (Keep CF flag intact)
        mov     ds,ax
        assume  ds:dgroup
        mov     ss,[word high saved_stack]
        mov     sp,[word low  saved_stack]
        assume  ss:@stack
        sti                             ; Set IF and clear DF
        cld                             ;   just in case...
        jc      exec_failed
        mov     ah,4dh                  ; Get Child-Program Return Value
        int     21h                     ;   into al register
        ; ...
        jmp short exit
    exec_failed:
        mov     al,0ffh
    exit:             
        mov     ah,4ch                  ; End Program, with return code
        int     21h

        SEGMENT top_of_mem para         ; Link a void segment last
        ENDS                            ;   to calculate top of memory
                                        ;   (don't use with DOSSEG)
        END start

See Also: 4b05h 3dh 4ah 4dh 59h PSP LoadExec

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