Reputation:
I am trying to execute .com file with specified arguments under MS-DOS 6.
I've found DOS 2+ - EXEC - LOAD AND/OR EXECUTE PROGRAM Int 21/AH=4Bh
The problem is, I don't know how exactly should I pass these parameters.
ES:BX should contain something called 'parameter block', but how to construct it? If i'd want to for example execute file named command.com with arguments /C ECHO HELLO WORLD
, how would I call this interrupt?
Code that I already have:
ORG 100H
START:
MOV AH, 4BH ;AH=>4BH
XOR AL, AL ;AL=>00H
MOV DX, CMD ;DS:DX=>STRING
MOV BX, PARAM;ES:BX=>PARAMS
INT 21H
MOV AH,4CH
INT 21H
CMD: DB "COMMAND.COM$" ;NOT SURE, SHOULD END WITH $
PARAM: ;???
How do i make my program do task mentioned earlier? As MS-DOS is nearly dead, and my assembler, NASM, is barely supported on this platform, I'm going to have bad time. My code may be poorly written as there are no resources about DOS.
Whole point of it is executing batch file generated on runtime by program.
Upvotes: 1
Views: 712
Reputation: 18521
CMD: DB "COMMAND.COM$" ;NOT SURE, SHOULD END WITH $
The only function that requires a string to end with $
is function 9 (print string). Most other functions require a string to end with NUL
(which is the byte with the value 0 - not the ASCII digit '0'
).
Just like this:
CMD DB "COMMAND.COM"
DB 0
The next problem you have is that a COM file gets nearly all available memory when being started.
Function 04Bh
will fail because there is not enough memory (because all the memory is "used" by the .COM file).
You have to use function 04Ah
to resize the memory block used by the .COM file before calling function 4Bh
:
push cs ; Only needed if ES != CS
pop es ; ...
mov bx, 1000h
mov ah, 4Ah
int 21h
PARAM: ;???
According to Ralph Brown's interrupt list this is 14 bytes long:
AFAIK the first byte of the command line is the number of bytes following, followed by the actual letters followed by the byte 0Dh
. (Check the content of cs:80h
to check this information.)
The FCBs are special representations of the first two command line arguments needed for DOS 1.x programs. Because they are not needed any more since DOS 2.x you can simply pass two dummy FCBs here. FCBs are 16 bytes long. You can simply "copy" the FCBs from your program (cs:05Ch
and cs:06Ch
) to the control block:
PARAM:
DW 0
DW CMDLINE
DW ??? ; Write CS here
DW 05Ch
DW ??? ; Write CS here
DW 06Ch
DW ??? ; Write CS here
CMDLINE:
DB xxx ; Replace by the length of the command line
DB "xxx" ; Replace by the actul command line
DB 0Dh ; Note: Not 0 but 0Dh in this case
Upvotes: 5