The EXE2BIN utility (EXE2BIN.EXE) transforms a .EXE file created by LINK into an executable .COM file, if the program meets the following prerequisites:
It cannot contain more than one declared segment and cannot define a stack.
It must be less than 64 KB in length.
It must have an origin at 0100H.
The first location in the file must be specified as the entry point in the source code's END directive.
Although .COM files are somewhat more compact than .EXE files, you should avoid using them. Programs that use separate segments for code, data, and stack are much easier to port to protected-mode environments such as MS OS/2; in addition, .COM files do not support the symbolic debugging information used by CodeView.
Another use for the EXE2BIN utility is to convert an installable device driver——after it is assembled and linked into a .EXE file——into a memory-image .BIN or .SYS file with an origin of zero. This conversion is required in MS-DOS version 2, which cannot load device drivers as .EXE files. The process of writing an installable device driver is discussed in more detail in Chapter 14.
Unlike most of the other programming utilities, EXE2BIN does not have an interactive mode. It always takes its source and destination filenames, separated by spaces, from the MS-DOS command line, as follows:
EXE2BIN sourcefile [destinationfile]
If you do not supply the source-file extension, it defaults to .EXE; the destination-file extension defaults to .BIN. If you do not specify a name for the destination file, EXE2BIN gives it the same name as the source file, with a .BIN extension.
For example, to convert the file HELLO.EXE into HELLO.COM, you would use the following command line:
C>EXE2BIN HELLO.EXE HELLO.COM <Enter>
The EXE2BIN program also has other capabilities, such as pure binary conversion with segment fixup for creating program images to be placed in ROM; but because these features are rarely used during MS-DOS application development, they will not be discussed here.