Assembly Source series of Exec

Source: Internet
Author: User

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.

; Execsub-execute program from compiled basic-requires DOS 2.00
; This version allows one BASIC program to call another
;
; Call Execsub (prog$,parm$,fcb1$,fcb2$,retcd%)
; prog$ is the program name (e.g. ' Command.com ')
; Parm$ is the "parameter to be passed to" program (e.g. '/C dir *.bas ')
; Fcb1$ is the "the" "required by some programs"
; Fcb2$ are the second file control blocks (required by some programs)
; retcd% is the error return code
Skip Equ 2; 1 for interpretive, 2 for compiled
CSEG segment para Public ' code '
Public execsub
execsub proc Far
Assume cs:cseg,ds:cseg,ss:nothing,es:nothing
Basicds equ 510h
I24IP equ 90h
I24CS equ 92h
I1BIP equ 6ch
I1bcs equ 6eh
I1CIP equ 70h
I1ccs equ 72h
B24IP equ 51ah
B24CS equ 51ch
B1BIP equ 516h
B1bcs equ 518h
B1CIP equ 512h
B1ccs equ 514h
Push BP
MOV bp,sp
JMP p010
Stak equ This byte
DW 0; Save SP
DW 0; Save SS
Prm1 equ This byte
DW 0; Environment
Prm2 EQU this word
DW 0; Command Line-ip & CS
DW 0
PRM3 equ This byte
DW 0; Default Fcb-ip & CS
DW 0
PRM4 equ This byte
DW 0; Second default FCB-IP & CS
DW 0
P010:
XOR Ax,ax; Get PSP
MOV es,ax; Es=0
MOV bx,ds; Save DS
MOV ds,ax; Ds=0
Cli
Push Ds:[basicds]; Save Basic ' s DS
Push DS:[I24IP]; Save int 24h and Shadow
Push Ds:[b24ip]
Push Ds:[b24ip]
Pop Ds:[i24ip]
Push Ds:[i24cs]
Push Ds:[b24cs]
Push Ds:[b24cs]
Pop ds:[i24cs]
Push DS:[I1BIP]; Save int 1bh and Shadow
Push Ds:[b1bip]
Push Ds:[b1bip]
Pop Ds:[i1bip]
Push Ds:[i1bcs]
Push Ds:[b1bcs]
Push Ds:[b1bcs]
Pop Ds:[i1bcs]
Push DS:[I1CIP]; Save int 1ch and Shadow
Push Ds:[b1cip]
Push Ds:[b1cip]
Pop Ds:[i1cip]
Push Ds:[i1ccs]
Push Ds:[b1ccs]
Push Ds:[b1ccs]
Pop Ds:[i1ccs]
STi
MOV ds,bx; Restore DS
MOV di,4f2h; Point to Dos Comm.
mov Ax,es:[di]; Get PSP Segment
MOV Es,ax
MOV di,2
mov Bx,es:[di]; Get top of memory
Sub Bx,ax; Subtract PSP
MOV Ah,4ah
int 21h; Free memory
Jnc p020; No error
MOV ah,0; Memory error
JMP p090; To the error control
P020:mov si,[bp+12]; Point to Parm$
Add Si,skip
MOV Ax,[si]
mov Si,offset prm2; Establish command line
MOV Cs:[si],ax
MOV Ax,ds
MOV Cs:[si+2],ax
mov si,[bp+10]; Point to fcb1$
Add Si,skip
MOV Ax,[si]
MOV Si,offset PRM3
MOV Cs:[si],ax
MOV Ax,ds
MOV Cs:[si+2],ax
mov si,[bp+8]; Point to fcb2$
Add Si,skip
MOV Ax,[si]
mov Si,offset PRM4; Establish second FCB
MOV Cs:[si],ax
MOV Ax,ds
MOV Cs:[si+2],ax
Push BP; Save Registers
Push DS
Push ES
Pushf
mov Si,offset Stak; Save Stack
MOV cs:[si],sp
MOV Cs:[si+2],ss
MOV ah,4bh; Load Prog
MOV al,0; Load & Execute
mov si,[bp+14]; Point to prog$
Add Si,skip
MOV Dx,[si]
Push CS
Pop es
mov Bx,offset prm1; Point to Parameter
int 21h; Load & Execute Program
Jnc p050; No error
MOV ah,1; Set error code
JMP p060
P050:mov ax,0; Clear Error
P060:mov Bx,cs; Restore stack
MOV ds,bx
MOV Si,offset Stak
CLI; No interrupts
MOV Sp,cs:[si]
MOV ss,cs:[si+2]
STI; Allow interrupts
Popf; Restore Registers
Pop es
Pop ds
Pop bp
MOV cx,ds; Save DS
XOR BX,BX
MOV ds,bx; Ds=0
Cli
Pop Ds:[b1ccs]; Restore int 1ch
Pop Ds:[i1ccs]
Pop Ds:[b1cip]
Pop Ds:[i1cip]
Pop Ds:[b1bcs]; Restore int 1bh
Pop Ds:[i1bcs]
Pop Ds:[b1bip]
Pop Ds:[i1bip]
Pop ds:[b24cs]; Restore int 24h
Pop ds:[i24cs]
Pop Ds:[b24ip]
Pop Ds:[i24ip]
Pop Ds:[basicds]; Restore basic ' s DS
STi
MOV ds,cx
P090:mov Si,[bp+6]; Point to retcd%
mov [Si],ax; Return error, if any
Pop bp; Return to caller
RET 10
Execsub ENDP
Cseg ends
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.