Solved

EXEC & parameter in ASM...

Posted on 1997-10-26
4
302 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

718 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