TITLE	Exec call test
PAGE	60,132

;  This program demonstrates shelling to DOS command processor
;  using the EXEC funtion.
;  Assemble, link and convert to a .COM file.
;  Program written by Brian M. Markey

code	SEGMENT	'codesg'
	ASSUME	CS:code,DS:code,ES:code

	ORG	0100H				; Program entry point
exectest:					;  ..

	MOV	SP,OFFSET stack			; Set up local stack

	MOV	AH,09H				; Print "Before shell"
	MOV	DX,OFFSET mess1			;  .
	INT	21H				;  ..

	MOV	BX,OFFSET lastloc+15		; BX := program size in
	MOV	CX,4				;  paragraphs
	SHR	BX,CL				;  ..

	MOV	AX,4A00H			; Deallocate unused memory
	INT	21H				;  ..

	MOV	SI,2CH				; Get environment address
	MOV	AX,CS:[SI]			;  from PSP+2CH
	MOV	WORD PTR parmblk,AX		;  ..

	MOV	AX,CS				; Set segment registers
	MOV	WORD PTR parmblk+4,AX		;  in paramater block
	MOV	WORD PTR parmblk+8,AX		;  .
	MOV	WORD PTR parmblk+12,AX		;  ..

	MOV	DX,OFFSET filenam		; Set up exec call
	MOV	BX,OFFSET parmblk		;  .
	MOV	AX,4B00H			;  ..

	PUSH	DS				; Save machine state
	PUSH	ES				;  .
	MOV	CS:savess,SS			;  .
	MOV	CS:savesp,SP			;  ..

	INT	21H				; Shell to DOS

	MOV	SP,CS:savesp			; Restore machine state
	MOV	SS,CS:savess			;  .
	POP	ES				;  .
	POP	DS				;  ..

	MOV	AH,09H				; Print "After shell"
	MOV	DX,OFFSET mess2			;  .
	INT	21H				;  ..

	INT	20H				; Terminate program

savess	DW	?				; Holders for SS:SP
savesp	DW	?				;  ..

mess1	DB	'Before shell',0DH,0AH,'$'
mess2	DB	'After shell',0DH,0AH,'$'

filenam	DB	'A:\COMMAND.COM',0		; Assume COMMAND.COM on A:

parmblk	DW	00				; Parameter block
	DW	OFFSET comline,00		;  .
	DW	5CH,00				;  .
	DW	6CH,00				;  ..

comline	DB	09H,'/C dir A:',0DH		; Command line

PAGE

	DB	128  DUP (?)			; Stack
stack	LABEL	BYTE				;  ..

lastloc	LABEL	BYTE				; End of program

code	ENDS
	END	exectest
