flat assembler
Message board for the users of flat assembler.

Index > DOS > Execute DOS .exe or .com program in FASM

Author
Thread Post new topic Reply to topic
cpcdos



Joined: 12 Aug 2013
Posts: 8
cpcdos 12 Aug 2013, 19:13
Hi!
I'm french *

I would like know how execute a DOS .exe or .com program in FASM ?

Thank. Smile
Post 12 Aug 2013, 19:13
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1625
Location: Toronto, Canada
AsmGuru62 12 Aug 2013, 20:04
I am not sure what are you asking.
To create an EXE or COM file for DOS -- there are examples of such programs in FASM package for DOS.
To execute the child EXE or COM from a parent program please follow this documentation:
http://www.ctyme.com/intr/rb-2939.htm
Post 12 Aug 2013, 20:04
View user's profile Send private message Send e-mail Reply with quote
cpcdos



Joined: 12 Aug 2013
Posts: 8
cpcdos 12 Aug 2013, 20:27
ho !
this is complicated for me ..
there are not code examples ?
Post 12 Aug 2013, 20:27
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1625
Location: Toronto, Canada
AsmGuru62 12 Aug 2013, 21:24
I do not understand your question.
What are you trying to do?
When you say: "execute EXE or COM" -- what do you mean?
Post 12 Aug 2013, 21:24
View user's profile Send private message Send e-mail Reply with quote
cpcdos



Joined: 12 Aug 2013
Posts: 8
cpcdos 12 Aug 2013, 23:42
I want to know (as a shell) running a another exe. (Child) with my fasm program
Post 12 Aug 2013, 23:42
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1625
Location: Toronto, Canada
AsmGuru62 13 Aug 2013, 10:56
I see... so you have a shell written in FASM and you want that shell to launch a DOS application.

If your shell is a DOS shell -- use that link I posted.
If your shell is a windows shell -- use CreateProcess() API to start a child program.
Also, try to use WinExec() API -- it has much less parameters than CreateProcess().

I do not have any working code for that.
Search this forum for WinExec or CreateProcess -- maybe someone already posted code you need.
Post 13 Aug 2013, 10:56
View user's profile Send private message Send e-mail Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 13 Aug 2013, 13:10
cpcdos wrote:
there are not code examples ?


Check the DOS related FAQ. In section X (Starting with real mode programming) says How to execute an external program in ASM?

DOS386 has spent a lot of time to organize all those links.
Post 13 Aug 2013, 13:10
View user's profile Send private message Visit poster's website Reply with quote
cpcdos



Joined: 12 Aug 2013
Posts: 8
cpcdos 15 Aug 2013, 10:56
Yes perfect ! thank you !

But how to execute a .exe format ?
I see this instruction

mov bx,10010h shr 4

for allocate 64ko, but if i want execute a .exe format, i just adjust memory ?
Post 15 Aug 2013, 10:56
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1902
DOS386 19 Aug 2013, 11:19
cpcdos wrote:
Yes perfect ! thank you ! But how to execute a .exe format ?


Same as DOS .COM, DOS will care.

> I see this instruction
> mov bx,10010h shr 4

Code:
MOV BX, $1001 ; $0001'0010 Byte's (64 KiB + 16 Byte's)    


> for allocate 64ko, but if i want execute a .exe format,
> i just adjust memory ?

Use MZ EXE format and "heap" for your code, no need to resize then.

AsmGuru62 wrote:
If your shell is a windows shell -- use CreateProcess() API to start a child program. Also, try to use WinExec() API -- it has much less parameters than CreateProcess(). I do not have any working code for that. Search this forum for WinExec or CreateProcess -- maybe someone already posted code you need.


This ^^^ is about spawning in Windows, NOT in DOS.

DOS: http://www.ctyme.com/intr/rb-2939.htm INT $21 / AH=$4B

Picnic wrote:
Check the DOS related FAQ. In section X (Starting with real mode programming) says How to execute an external program in ASM?


Updated, now in section C Smile
Post 19 Aug 2013, 11:19
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 17 Oct 2013, 19:00
You can launch any file (.exe .txt etc) by using this code

Code:
invoke ShellExecuteA,NULL,NULL,filepathandname,NULL,NULL,SW_NORMAL
    


just add this to the idata section of your code

Code:
library Shell32,'Shell32.dll'

import Shell32,\
ShellExecuteA,'ShellExecuteA'
    


You must have a computer that is running windows xp or later to use this code
Post 17 Oct 2013, 19:00
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 18 Oct 2013, 12:40
patchariadog wrote:
You must have a computer that is running windows xp or later to use this code

The ShellExecute function is also available in Win9x, especially the ANSI version. MSDN says that minimal OSes are Windows NT 3.1, Windows 95.
Post 18 Oct 2013, 12:40
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 18 Oct 2013, 13:55
oh I did not know that, thanks!
Post 18 Oct 2013, 13:55
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 204
ACP 23 Oct 2013, 17:42
I seem to recall that HX dos extender does not support ShellExecuteW but I don't remember if ShellExecuteA is supported. If it is than actually you might run it under DOS+HX Wink
Post 23 Oct 2013, 17:42
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1902
DOS386 25 Oct 2013, 17:35
ACP wrote:
I seem to recall that HX dos extender does not support ShellExecuteW but I don't remember if ShellExecuteA is supported. If it is than actually you might run it under DOS+HX Wink


ShellExecuteA YES
ShellExecuteExA YES
ShellExecuteW NO
ShellExecuteExW NO

Note that HELL-EXECUTE just wraps deprecated WinExec function which then wraps BrewProcess function, and with HX this goes to DPMILD32 using enhanced INT $21/AX=$4Bxx ... so this is NOT the preferred straightforward way to spawn in DOS Wink

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 25 Oct 2013, 17:35
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 14 Nov 2013, 11:02
DOS386 wrote:
cpcdos wrote:
Yes perfect ! thank you ! But how to execute a .exe format ?


Same as DOS .COM, DOS will care.

> I see this instruction
> mov bx,10010h shr 4
Code:
MOV BX, $1001 ; $0001'0010 Byte's (64 KiB + 16 Byte's)    

> for allocate 64ko, but if i want execute a .exe format,
> i just adjust memory ?

Use MZ EXE format and "heap" for your code, no need to resize then.

I like to free up the memory with calculating the number of bytes that our MZ EXE is needed and then using int 21h/ah=4Ah for to resize the memory.
(Just doing it before we manipulate the ES-segment register for an other reason.)
Code:
mov   bx, ss  ; first we subtract the address in ES 
mov   ax, es  ;  from the address in SS
sub   bx, ax  ; the result is the number of paragraphs
              ;  from our PSP to the beginning of our stack

mov  ax, sp   ; because the stackpointer points to the end of our stacksegment
add  ax, 0Fh  ;  we become with the content of SP the length of our stack(+round up)
shr  ax, 4    ; converting to paragraphs
add  bx, ax   ; adding to the length 
mov  ah, 4Ah  ; Input: BX= new size in paragraphs
int  21h      ; ES= segment of block to resize
    

RESIZE MEMORY BLOCK Int 21/AH=4Ah
http://www.ctyme.com/intr/rb-2936.htm

;-------------------------------------------------------------

Some additional words for to execute a child-program using the 4Bh EXEC-function if the child want to get and search for some own commandline parameter: We have to get the current PSP address before we can get the commandline. Because the current PSP is not necessarily the caller's PSP. (I saw many codelistings are only pointing to CS:80h... without for to get the current PSP address before.)

GET CURRENT PSP ADDRESS Int 21/AH=62h
http://www.ctyme.com/intr/rb-3140.htm

Dirk
Post 14 Nov 2013, 11:02
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.