• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

EXEC & parameter in ASM...

Do you know how to execute a program and to access to the programmer parameters from an ASM program?
0
kilobug
Asked:
kilobug
  • 2
1 Solution
 
fasterCommented:
What platform?
0
 
nietodCommented:
Assuming DOS.

use DOS function 4BH.  
     DS:DX points to a NUL terminated string that specifies the path and name of the EXE.
     ES:BX points to a parameter block that specifies the parameters (and environment strings.)

This call changes the stack segment and pointer so you mustsave these values.

.DATA
EXEPTHNAM DB "C:\TEST.EXE",0
CMDLIN    DB "Parameter string to pass",0

PRMBLK    LABEL WORD
ENVSEG    DW ? ; Initialize to specify environment strings segment.
CMDLINSEG DW SEG DATA ; Segment of command line string.
CMDLINSEG DW CMDLIN   ; Offset of command line string.
FCB1   DD 0 ; -> default FCB 1.  Can usually be left NULL.
FCB2   DD 0 ; -> default FCB 2.  Can usually be left NULL.

.CODE
SAVPTR DW 0
SAVSEG DW 0

 * * *
 
 MOV AH,4BH       ; Indicate EXEC function.
 MOV AL,0         ; Indicate run sub-function.
 LDS DX,EXEPTHNAM ; Load pointer to EXE path and name.
 LES BX,PRMBLK    ; Load pointer to parameters.
 MOV CS:SAVSEG,SS ; Save the stack segment.
 MOV CS:SAVPTR,SP ; Save the stack pointer.
 INT 21H          ; Execute specified program.
 LSS SP,CS:SAVPTR ; Restore stack information.
 JC ERRHANDLER    ; If carry, go handle error.

This is the gist of the process.  Setting up the parameter block varies depending on what you want to do.  Often just set the environment segment to your program's environment segment.  The FCB pointers can also be set to your program's, but almost no programs used FCBs so they can usually be ignored.
0
 
Jackie071497Commented:
1. Exec program : use int 21h ( ah = 4ah & 4bh )

pgname db 'TEST.EXE',0
pblock db 0

push ds
pop es ; let ES = PSP address
mov bx,2048/16 ; suppose 2K memory needed for TEST.EXE
mov ah,4ah ; re-allocate
int 21h
lea dx,pgname
push cs
pop es
lea bx,pblock ; parameter block
mov ax,4b00h ; exec
int 21h
JC error ; if error -->

2. Get parameters : use PSP:[80h] & [81h]...

ProgramStart:
   mov ax,ds
   mov cs:PSPAddress,ax
   mov es,ax
   mov si,080h ;get DOS parameters
   xor ch,ch
   mov cl,byte ptr es:[si]
   jcxz NoParameter
BypassSpace:
   inc si
   cmp byte ptr es:[si],020h
   ja ParseParameter
   dec cx
   jcxz NoParameter
   jmp BypassSpace
ParseParameter:
   mov cs:ParameterTemp,'/' ;default parameter error
   cmp byte ptr es:[si],'/'
   jne NoParameter
   mov al,byte ptr es:[si+1] ;get acture parameter
   mov cs:ParameterTemp,al
NoParameter:

0
 
nietodCommented:
jackie put in some details that I skipped and skipped som I put in.  You'll kinda want to combine them.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now