Solved

EXEC & parameter in ASM...

Posted on 1997-10-26
4
292 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
Comment Utility
What platform?
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
jackie put in some details that I skipped and skipped som I put in.  You'll kinda want to combine them.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now