Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

EXEC & parameter in ASM...

Posted on 1997-10-26
4
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

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

Accepted Solution

by:
nietod earned 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

636 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