Solved

EXEC & parameter in ASM...

Posted on 1997-10-26
4
301 Views
Last Modified: 2006-11-17
Do you know how to execute a program and to access to the programmer parameters from an ASM program?
0
Comment
Question by:kilobug
  • 2
4 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1172101
What platform?
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1172102
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
 
LVL 3

Expert Comment

by:Jackie071497
ID: 1172103
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
 
LVL 22

Expert Comment

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

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question