Assembly Language Help (alang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Exec
 Map                                       Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
;* Exec - Executes a child process.  Exec handles the usual chores associated
;* with spawning a process:  (1) parsing the command line tail and loading the
;* FCBs with the first two arguments; (2) setting and restoring the vectors
;* for Interrupts 1Bh, 23h, and 24h; and (3) querying DOS for the child's
;* return code.
;*
;* Shows:   DOS Functions - 29h (Parse Filename)
;*                          25h (Set Interrupt Vector)
;*                          35h (Get Interrupt Vector)
;*                          4Bh (Execute Program)
;*                          4Dh (Get Return Code)
;*
;* Params:  Spec - Pointer to ASCIIZ specification for program file
;*                 (must include .COM or .EXE extension)
;*          Block - Pointer to parameter block structure
;*          CtrBrk - Pointer to new Ctrl+Break (Interrupt 1Bh) handler
;*          CtrlC - Pointer to new Ctrl+C (Interrupt 23h) handler
;*          Criterr - Pointer to new Critical Error (Interrupt 24h) handler
;*
;* Return:  Short integer with child return code, or -1 for EXEC error
 
Exec    PROC USES ds si di,
        Spec:PBYTE, Block:PPARMBLK, CtrBrk:PTR FAR,
        CtrlC:PTR FAR, Criterr:PTR FAR
 
        Vector 1Bh, Old1Bh, CtrBrk      ; Save, replace Int 1Bh vector
        Vector 23h, Old23h, CtrlC       ; Save, replace Int 23h vector
        Vector 24h, Old24h, Criterr     ; Save, replace Int 24h vector
 
        LoadPtr ds, bx, Block           ; Point DS:BX to parameter block
        push    ds                      ; Save segment address
        les     di, (PARMBLK PTR [bx]).\\; Point ES:DI to first FCB
                    fcb1
        lds     si, (PARMBLK PTR [bx]).\\; Point DS:SI to command line tail
                    taddr
        inc     si                      ; Skip over count byte
 
        mov     ax, 2901h               ; Set AH to request Function 29h
                                        ; AL = flag to skip leading blanks
        int     21h                     ; Parse command-line into first FCB
        pop     es                      ; Recover seg addr of parameter block
        les     di, \\                   ; Point ES:DI to second FCB
                    (PARMBLK PTR es:[bx]).fcb2
        mov     ax, 2901h               ; Request DOS Function #29h again
        int     21h                     ; Parse command-line into second FCB
 
        push    bp                      ; Save only important register
        mov     WORD PTR cs:OldStk[0], sp
        mov     WORD PTR cs:OldStk[2], ss
        LoadPtr es, bx, Block           ; ES:BX points to param block
        LoadPtr ds, dx, Spec            ; DS:DX points to path spec
        mov     ax, 4B00h               ; AH = DOS Function 4Bh
                                        ; AL = 0 for load and execute
        int     21h                     ; Execute Program
        mov     sp, WORD PTR cs:OldStk[0] ; Reset stack pointers
        mov     ss, WORD PTR cs:OldStk[2]
        pop     bp                      ; Recover saved register
 
; Restore vectors for Interrupts 1Bh, 23h, and 24h.
 
        mov     ax, 251Bh               ; AH = DOS Function 25h
                                        ; AL = interrupt number
        lds     dx, cs:Old1Bh           ; DS:DX = original vector
        int     21h                     ; Set Interrupt 1Bh Vector
        mov     al, 23h                 ; AL = interrupt number
        lds     dx, cs:Old23h           ; DS:DX = original vector
        int     21h                     ; Set Interrupt 23h Vector
        mov     al, 24h                 ; AL = interrupt number
        lds     dx, cs:Old24h           ; DS:DX = original vector
        int     21h                     ; Set Interrupt 24h Vector
 
        mov     ax, -1                  ; Set error code
        .IF     !carry?                 ; If no EXEC error:
        mov     ah, 4Dh                 ; Request child's code
        int     21h                     ; Get Return Code
        sub     ah, ah                  ; Make short integer
        .ENDIF
        ret
 
Old1Bh  FPVOID  ?                       ; Keep vectors for Interrupts
Old23h  FPVOID  ?                       ;   1Bh, 23h, and 24h in code
Old24h  FPVOID  ?                       ;   segment, but non-executable
OldStk  FPVOID  ?                       ; Keep stack pointer
 
Exec    ENDP
                                    -♦-