
 use16
 org 0100h
 
	; set up parameter block
	mov di,pblk
	cld
	mov ax,[2Ch] ; at 2ch in our PSP is the value of env. segment
	stosw	      ; store in the pblock
	mov ax,ds    ; the other 3 segments are the same as our ds
	mov cx,3 
.l1: 	inc di	 ; skip the offset value
     	inc di
     	stosw	 ; store segment value
     	loop .l1	
	mov [backup_ds_ss],ax ; save ds/ss/sp as they may be destroyed
	mov [backup_sp],sp			
	
	; now free some memory for the other prog 
	mov bx,bottom	; adress of end of our program
	shr bx,4	; convert to paragraph
	inc bx		; round up
	mov ah,4ah	; shrink
	int 21h

	; run it
	mov dx,prog	; asciiz path to prog
	mov bx,pblk	; parameter block
	xor al,al 	; 0=load & execute
	mov ah,4bh
	int 21h
	mov ax,[backup_ds_ss] ; restore
	mov ss,ax
	mov ds,ax
	mov sp,[backup_sp]	
	jc .fail
	ret
.fail:	mov dx,failure_msg
	mov ah,09h
	int 21h
	ret

; parameter block
pblk:
 dw 0    ; environment segment 
 dw args ; cmd line offset (or 80h to inherit our cmdline)
 dw 0    ; cmd line segment
 dw fcb1 ; fcb1 offset
 dw 0    ; fcb1 segment
 dw fcb2 ; fcb2 offset
 dw 0    ; fcb2 segment

backup_ds_ss: dw 0 
backup_sp: dw 0

fcb1: times 16 db 0
fcb2: times 16 db 0
args: db (.e - args) -1
      db ' *.txt',0dh
.e:
prog: db 'd:\test\attrib.exe',0 
failure_msg: db 'error!$'

bottom:
