This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.
Name FXN4BH
Page 55,132
Title ' FXN4BH---demo pc-dos EXEC function '
;
; FXN4BH---Demonstrate use of the
; Pc-dos 2.0 EXEC Function call 4BH
;
; Copyright (c) 1983 by Ray Duncan
;
CR Equ 0DH; ASCII Carriage return
LF equ 0ah; ASCII line Feed
;
CSEG segment para public ' CODE '
;
Assume Cs:cseg,ds:data,ss:stack
;
Demo proc Far
; at entry DS & ES = PSP
Push DS; Save Address for final
XOR Ax,ax; FAR RET to Pc-dos on stack
Push AX
; Save copy of SS:SP for use
; After return from overlay
MOV Cs:stk_seg,ss
MOV cs:stk_ptr,sp
;
; Reserve 1000H bytes for
; This loader and release
; the rest of memory for
; by the overlayed program.
mov bx,100h es=segment of PSP of loader
MOV ah,4ah; Bx=paragraphs to reserve
int 21h
; Make the messages in data
; segment addressable
MOV ax,seg DATA
MOV Ds,ax
MOV Es,ax
; Jump if memory
;d E-allocation failed
JC Alloc_err
;p rint Memory successfully
; released
MOV Dx,offset MSG2
MOV ah,9
int 21h
;
; now load and execute
; the overlaid program.
MOV Dx,offset pgm_name
MOV Bx,offset par_blk
MOV al,0
MOV AH,4BH
int 21h
; Restore stack pointers
; to the state before EXEC call
MOV ss,cs:stk_seg
MOV sp,cs:stk_ptr
; Make data segment
; addressable again
MOV ax,seg DATA
MOV Ds,ax
;P rint message that loader
; Successfully regained control
MOV Dx,offset MSG3
MOV ah,9
int 21h
; now exit to Pc-dos
Ret
Alloc_err:; Come here if memory
; cannot be released
MOV Dx,offset MSG1
MOV ah,9
int 21h;p rint error message and
ret; exit to Pc-dos
;
Demo ENDP
;
; These two variables must
; reside in Code Segment so
; that they are addressable
; after return to overlay.
Stk_seg DW 0; original SS contents
Stk_ptr DW 0; original SP contents
;
Cseg ends
;d Eclare a stack area
; for use by this loader
Stack segment para stack ' stack '
; Allow bytes in the case
DB DUP (?)
Stack ends
;d Eclare Data Segment to
; Contain variables and tables
Data segment para public ' data '
;
MSG1 DB CR,LF
DB ' Unable to release memory. '
DB Cr,lf, ' $ '
MSG2 DB CR,LF
DB ' Memory above loader released. '
DB Cr,lf, ' now loading chkdsk.com. '
DB Cr,lf, ' $ '
MSG3 DB CR,LF
DB ' Loader regained control from CHKDSK, '
DB CR,LF
DB ' now making final exit to Pc-dos. '
DB Cr,lf, ' $ '
;
;d rive, Path, and name of program
; to be loaded and executed.
Pgm_name db ' CHKDSK. COM ', 0
;
PAR_BLK DW envir segment address of
; Environment descriptor
;
; Full Address ' command line
; To is passed at offset 80H
DW offset Cmd_line in overlaid
DW seg cmd_line;p rogram ' s PSP
;
; Full address of default
; File control blocks to IS
;p at offset 5CH in
DW offset FCB1; overlaid
DW seg FCB1;p rogram ' s PSP
;
; Full address of default
; File control blocks to IS
;p at offset 6CH in
DW offset FCB2; overlaid
DW seg FCB2;p rogram ' s PSP
;
; actual command line tail
; To is passed to overlay
Cmd_line db 4, ' *.* ', cr,0
;
; the FCB to
FCB1 DB 0 passed to overlay
DB one DUP ('? ')
DB DUP (0)
; second default FCB to
FCB2 DB 0 passed to overlay
DB one DUP (')
DB DUP (0)
;
Data ends
;d eclare Separate data
; segment to contain
; Environment descriptor
EnviR segment para ' envir '
;
; Search path used by Pc-dos
; to look for commands or
; Batch files not found in
DB ' path= ', 0; the current directory
;
; Search path used by Pc-dos
; To locate Command.com
DB ' Comspec=a:command. COM ', 0
DB 0 Extra 0 byte designates
; End of environment
EnviR ends
End Demo