I am writing some little tools for MS-DOS. Now I'm writing a Shutdown.com
, like for Windows XP and greater. I have already written the entire code, now I just need to pass the argument from DOS.
I need to pass the parameters "-r" to reboot and "-s" to shutdown.
How can I do it?
I'm using TASM(Turbo Assembler 4.1) on Windows 98 to link and compile. I'm looking for a very simple way to do it, and if possible, still a .COM
program. I'm looking exactly like the ARGV and ARGC from C language, but for Assembly 16-bits...
shutdown -r
will rebootshutdown -s
will shutdown
Remember that I already know how to reboot and how to shutdown the PC.
I just need to learn how to pass the parameters from the MS-DOS command line to my program.
There is no specific API to retrieve the command-line in MS-DOS. Instead, you have to read the value from the appropriate offset of the Program Segment Prefix (PSP), which is a data structure that DOS uses to store program-specific data.
At offset 80h, there is a 1-byte value that gives the length of the command-line arguments. The actual command-line argument string starts at offset 81h, and can be up to 127 bytes in length. You know how long it is based on the value at offset 80h, but it will also be terminated with a carriage return (0Dh).
You can use these offsets relative to the pointer in the
DS
register when the program is first executed. Otherwise, you callINT 21h
withAH
set to62h
to retrieve a pointer to the current PSP in theBX
register. (Function62h
requires DOS 3 or later; on DOS 2, you can use the undocumented function51h
).The old, 16-bit DOS version of Randall Hyde's Art of Assembly is available for free online (in HTML and PDF formats). In Chapter 13, section 13.3.11 describes the PSP, and the following two sections (13.3.12–13) explain how to access and parse command-line parameters, including sample code.