flat assembler
Message board for the users of flat assembler.

Index > DOS > Exetute external program under TASM

Author
Thread Post new topic Reply to topic
sgabor68



Joined: 09 Sep 2025
Posts: 3
sgabor68 09 Sep 2025, 13:33
Hello. Just a small question... I have tried for a long time how to execute an external program in assembly language, but it's not working.
Please help me!!! How can I execute an external program using TASM ??
Post 09 Sep 2025, 13:33
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1183
Location: Russia
macomics 09 Sep 2025, 14:39
TASM is a compiler. It doesn't run external programs on execution. The operating system does this.

If you're talking about TASM, then it's probably DOS. Although there is also TASM32 for Windows.

Under DOS, you have the INT21h 4Bh function to run external program. But in order for it to work, you need to reduce the memory size for your program (INT21h 4Ah function). Then DOS will be able to allocate the freed memory for the running program.

For Windows, you have kernel32.lib (import32.lib) and the CreateProcessA function.
Post 09 Sep 2025, 14:39
View user's profile Send private message Reply with quote
sgabor68



Joined: 09 Sep 2025
Posts: 3
sgabor68 10 Sep 2025, 07:47
Thank you for your help, I'll try. I only mentioned that I use TASM because other compilers like FASM can indicate syntax errors within the program.
Post 10 Sep 2025, 07:47
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1731
Location: Toronto, Canada
AsmGuru62 10 Sep 2025, 15:24
1. Please tell us what Operating System you are using to run the external program.
2. Please post the FASM code which shows the syntax errors.
Post 10 Sep 2025, 15:24
View user's profile Send private message Send e-mail Reply with quote
sgabor68



Joined: 09 Sep 2025
Posts: 3
sgabor68 11 Sep 2025, 07:42
Hello.
I would like to run the DOS command line interpreter (cmd.exe) found in Windows system32 under a DOS operating system. I tried a code snippet, but it is probably interpreted by FASM only because TASM gives syntax errors (4).
The code:

org 100h

; first, we need to free the conventional memory we don't use,
; so there will be some memory available for the program we want
; to run, if we used MZ format of executable, the directive
; "heap 0" would be enough for this purpose, in case of .com
; program we have to free that memory manually be resizing the
; memory block starting at our PSP (es is already set to it)

mov ah,4Ah ; resize memory block
mov bx,10010h shr 4 ; only memory needed for .com
int 21h

; now set up the pointer to command line in the parameters block

mov word [cmdline],_command
mov word [cmdline+2],ds

; we are ready to execute the program now

mov ax,4B00h ; load and execute program
mov dx,_program ; ASCIIZ path of program
mov bx,params ; parameter block
int 21h

int 20h ; exit program


_program db 'c:\command.com',0
_command db 0 ; length of command line
db 13 ; must end with CR character

params:
environment dw 0 ; segment of environment, 0 means to use parent's one
cmdline dd ? ; pointer to command line
default_fcb1 dd 0 ; pointers to file control blocks
default_fcb2 dd 0

Thanks if you have some good advice.
Post 11 Sep 2025, 07:42
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1183
Location: Russia
macomics 11 Sep 2025, 09:07
That's right. This is a fragment of the program for fasm.

The syntax is slightly different for TASM. If I haven't forgotten all the features yet, then for TASM this program will look like this.
Code:
.386
.model small
segment text
assume cs:text, ds:text, es:text
org 100h

; first, we need to free the conventional memory we don't use,
; so there will be some memory available for the program we want
; to run, if we used MZ format of executable, the directive
; "heap 0" would be enough for this purpose, in case of .com
; program we have to free that memory manually be resizing the
; memory block starting at our PSP (es is already set to it)
startup:
mov ah,4Ah ; resize memory block
mov bx,1001h ; only memory needed for .com
int 21h

; now set up the pointer to command line in the parameters block

mov word ptr cmdline,_command
mov word ptr cmdline[2],ds

; we are ready to execute the program now

mov ax,4B00h ; load and execute program
mov dx,offset _program ; ASCIIZ path of program
mov bx,offset params ; parameter block
int 21h

int 20h ; exit program


_program db 'c:\command.com',0
_command db 0 ; length of command line
db 13 ; must end with CR character

params:
environment dw 0 ; segment of environment, 0 means to use parent's one
cmdline dd ? ; pointer to command line
default_fcb1 dd 0 ; pointers to file control blocks
default_fcb2 dd 0
ends text
end startup    
Post 11 Sep 2025, 09:07
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8439
Location: Kraków, Poland
Tomasz Grysztar 11 Sep 2025, 09:59
macomics wrote:
The syntax is slightly different for TASM. If I haven't forgotten all the features yet, then for TASM this program will look like this.
You forgot about the OFFSET keyword:
Code:
mov word ptr cmdline,offset _command
mov word ptr cmdline[2],ds    
Also, since 386 is specified, the segment needs USE16 marker:
Code:
segment text use16    
Otherwise in MASM-compatible mode 32-bit would be default, immediately noticeable thanks to "Offset or pointer is 32-bit" errors.

And switching to "ideal" mode would make it a bit closer to fasm:
Code:
ideal
p386
model small
segment text use16
assume cs:text, ds:text, es:text
org 100h    

Code:
mov [word cmdline],offset _command
mov [word cmdline+2],ds    
Post 11 Sep 2025, 09:59
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1731
Location: Toronto, Canada
AsmGuru62 11 Sep 2025, 13:12
Please correct me, but I think that CMD.EXE found in Windows OS is not a DOS executable file.
Post 11 Sep 2025, 13:12
View user's profile Send private message Send e-mail Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 64
Location: Czech republic
Hrstka 12 Sep 2025, 08:25
Trying to run a Windows program under DOS usually results in a message "This program cannot be run in DOS mode" and termination.
Post 12 Sep 2025, 08:25
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.