Hmm... it looks like mail... mmmh, it tastes like mail... it _is_ mail!
Once upon a time (Tuesday, April 29, 1997 to be precise), Robert Horne wrote
letter to All about "External Programs"...
RH> Hi all! Can somebody tell me how to execute external programs, such as
RH> EXE or COM files in assembler?
Sure! This should do the trick:
======
; start your program by minimizing your programs memory usage
mov bx,sp
add bx,15
shr bx,4 ; stack size in para's
mov ax,ss
add bx,ax ; bx points to end of stack
mov ax,es ; es points to psp at
sub bx,ax ; beginning of program
mov ah,4ah ; resize memory block
int 21h
jc error ; unlikely, but still... :)
.
.
.
; later (the actual exec call)
mov ax,da ; da is the data segment
mov ds,ax
mov es,ax
mov ax,4b00h ; call dos
lea dx,p_name
lea bx,p_block
int 21h
.
.
.
; and, in the data segment (da)
p_name db "M.EXE",0 ; name of program to run
p_block label byte
dw 0 ; [1]
dd cmdtail ; pointer to cmdtail
dd fcb1 ; pointer to fcb1
dd fcb2 ; pointer to fcb2
cmdtail db 0,0dh ; [2]
fcb1 db 0 ; [3]
db 11 dup ("?")
db 25 dup (0)
fcb2 db 0
db 11 dup (" ")
db 25 dup (0)
; [1] this is the segment pointer to the environment table to be used by
; the child program. a value of 0 makes dos produce and use a copy of
; the running programs psp. you should therefore always use 0 here.
; [2] the command tail is in the format ,"",0dh.
; does not include the 0dh byte.
; [3] i don't remember if the "?" in fcb1 is necessary. :-/
======
RH> I have a reference, but I couldn't get it to work.
Then perhaps you need a better reference. :)
RH> Thanks for any help!
You're welcome. :)
Oh yeah, one last thing. In DOS 2.0, all registers except for CS and IP are
destroyed by function 4B00h. The problem does not exist in DOS 3.0+.
(Let's just pretend you actually needed to know that.. :)
("`-/")_.-'"``-._
O O `; -._ )-;-,_`)
=(_~_)= _ )`-.\ ``-' - Flemming Sondergaard
_.-~_..-_/ / ((,'
((,.-' ((,/
--- Terminate 4.00/Pro
---------------
* Origin: System busy: Windows loading - Come back tomorrow. (2:237/45.15)
|