TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: ROBERT HORNE
from: DAVID KIRSCHBAUM
date: 1997-05-01 09:07:00
subject: External Programs

 > Hi all!  Can somebody tell me how to execute external programs,
 > such as EXE or COM files in assembler?  I have a reference, but
 > I couldn't get it to work. Thanks for any help!
 > Robert Horne
I'd stronlgy recommend the following two packages, at any SimTel mirror site 
on the internet (or their CD-ROMs):
  asmutl tbones07.zip  34K 910119 Skeletal ASM programs for programming TSRs
  asmutl tsrdemo2.zip  15K 870308 Sample demo on a safe approach to TSRs 
(w/ASM)
Alternatively, my own old (but still functional) TOADEXEC.  The core came 
from Brian Markey's code, and then I did some more (well, a lot more) 
tweaking.
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
;v1.1 Toad Hall Tweak, 30 Jun 88
; - Accepts up to 125 chars at regular DOS command line.
; - If no DOS command line, defaults to COMMAND.COM shell
;       (EXIT to exit).
; - Slightly more tweaking Feb 89
; David Kirschbaum
; Toad Hall
; kirsch@braggvax.ARPA
; Boy that dates me!  try kirschd@hq.ljl.com or kirschd@ibm.net
CR      equ     0DH
LF      equ     0AH
CSEG    SEGMENT PUBLIC PARA 'CODE'
        ASSUME  CS:CSEG,DS:CSEG,ES:CSEG
        org     0
SEG_ORG equ     $
        org     2CH
envaddr dw      ?                               ;Environment address
        org     80H                             ;PSP cmd line
PSPcmdline      db      ?
        ORG     100H                            ; Program entry point
ExecTest        proc    near
        jmp     Start
saveSS  DW      0                               ; Holders for SS:SP
saveSP  DW      0
mess1   DB      'Before shell',0
mess2   DB      'After shell',0
crlf    db      CR,LF,0
filenam DB      'C:\COMMAND.COM',0              ; Assume COMMAND.COM on C:
        Even                                    ;for faster access?
;EXEC parameter block
parmblk DW      0                               ;gets stuffed with parent
                                                ;program's environ addr
;Rest of 0's get filled with our CSEG
        DW      OFFSET comline,0                ;default cmdline to use
        DW      5CH,0                           ;vector to our PSP FCB #1
        DW      6CH,0                           ;vector to our PSP FCB #2
        IF1
COMLEN  =       0                               ;init for pass 1
        ENDIF
; default is just COMMAND.COM
comline db      COMLEN  ;17                     ;default cmd length
        db      '/C C:\COMMAND.COM'             ;default: Exec COMMAND.COM
COMLEN  =       $ - offset comline - 1          ;length (not including
                                                ;length byte)
        db      0DH                             ;terminate with CR
COMLEN2 =       $ - offset comline              ;full command length
        db      128-COMLEN2 DUP(0)              ;pad up to 128 bytes
ExecTest        endp
Start   proc    near
        MOV     SP,OFFSET OURSTK                        ; Set up local stack
        mov     si,offset mess1                 ;'Before shell'
        call    Writeln
        mov     bx,PROGSIZE                     ;program size in paras
        MOV     AX,4A00H                        ; Deallocate unused memory
        INT     21H
        mov     ax,CS                           ;insure DS=CS
        mov     ES,ax                           ;for PSP move
        mov     ax,envaddr                      ;get environment addr
        mov     bx,offset parmblk               ;point to parameter block
        MOV     [bx],AX                         ;stuff in environ seg
        MOV     AX,CS                           ; Set segment registers
        MOV     4[bx],AX                        ;  in parameter block
        MOV     8[bx],AX                        ; to our Code Seg
        MOV     12[bx],AX                       ;
; move PSP command line into our own working buffer
        mov     si,offset PSPcmdline            ;point to PSP cmd line
        mov     di,offset comline               ;point to our own cmd line 
buff
        xor     ax,ax                           ;insure msb is clear
        cld                                     ;insure fwd
        lodsb                                   ;snarf cmd line length byte
        mov     cx,ax                           ;into cx as a counter
        jcxz    No_Cmd                          ;empty, use default
; SI now points to first char of PSP cmd line
        inc     ax                              ;+2 for '/C' already there
        inc     ax
        stosb                                   ;force working cmd line len
        inc     di                              ;bump past "/C"
        inc     di
        rep     movsb                           ;transfer cmd line
No_Cmd:
;end of Toad Hall code
;Set up EXEC call
        MOV     DX,OFFSET filenam               ;Command processor path\name
;       MOV     BX,OFFSET parmblk
        MOV     AX,4B00H                        ;EXEC
                                                ;BX = offset parmblk
        PUSH    DS                              ; Save machine state
        PUSH    ES
        mov     saveSS,SS
        mov     saveSP,SP
        INT     21H                             ; Shell to DOS
; seem to recall something about disabling interrupts
; before fiddling these registers, but can't remember just what!
; Seems to work ok, so will leave it be for now.
        MOV     SS,CS:saveSS                    ;restore machine state
        MOV     SP,CS:saveSP                    ;(no CLI required)
        POP     ES
        POP     DS
        pushf                                   ;save flags
        push    ax                              ;and EXEC error value
        mov     si,offset mess2                 ;'After shell'
        call    Writeln
;       INT     20H                             ; Terminate program
        pop     ax                              ;restore EXEC error
        popf                                    ;and EXEC flags
        mov     ah,4CH                          ;terminate
        int     21H
Start   endp
;Display AsciiZ string, then CR/LF
Writeln proc    near
        call    Pr_AsciiZ               ;display string
        mov     si,offset crlf          ;now the CR/LF
                                        ;...fall thru to ...
Writeln endp
;Display AsciiZ string
Pr_AsciiZ       proc    near
        lodsb                           ;str char
        or      al,al                   ;AsciiZ terminator?
        jz      Pr_AsciiZ_X             ;yep
        mov     ah,0EH                  ;write TTY
        int     10H                     ;via BIOS
        jmp     short Pr_AsciiZ
Pr_AsciiZ_X:
        ret
Pr_AsciiZ       endp
        EVEN
CODEND  equ     $
OURSTK  equ     CODEND + 256
PROGSIZE EQU    (OURSTK - SEG_ORG + 15) SHR 4           ;size in paras
CSEG    ENDS
        END     ExecTest
---
 > HeY DuDEs!!!!
 > I just found a k-rad file of a warez site -- it's a list of ALL
 > THE INTERRUPTS, by some guy named Ralf Brown. I thought I'd
 > post it so u lamerz could see it. It's only a couple megs,
 > dude...
Ko0L!  Except my mailer can't handle anything longer than 75 lines, so could 
you break them up a little smaller, huh?
;-)
 > Just kidding. (:
 > Asher Densmore-Lynn 
 > ---
 >  ~ TLX v4.10 ~ There's at least one fool in every married couple.
---
---------------
* Origin: Toad Hall (1:3634/2.4)
* Origin: Toad Hall (1:3634/2.4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.