DOS executable (.com)
Introduction
On DOS and early Windows systems, files with extension .com are a special type of 16 bit executable which most of the time can only be run from the commandline. The extension comes from CP/M and stands for "command program" (or some variant thereof). As such they predate the more common EXE format, and are quite limited compared to the newer format:
- COM files contain only one area of combined code and data. There is no segmentation, no seperate code and data segments, and (more importantly) no relocation table
- They contain the raw program binary, without any header, which will be mapped into memory at a specific offset (
0x100
) in a (possibly random) segment. Thus they resemble some arbitrary ROM (.bin) format. - They can be at most around 64kb big (65280 bytes to be exact)
- They can only use relative adressing, since the position in memory where they are loaded is not known to the program (but can be determined through an API call)
A good example is command.com, the 16 bit command line interface of MS-DOS.
Since COM files contain directly executable code, most of them start with a simple 0xe9
or oxeb
byte, representing a short JUMP to the "real" entry point of the program. But this is not set in stone, and there are lots of COM files that have a different first byte
Sometimes, COM files are larger than 64kb and start with a "MZ" or "ZM" signature in the first 2 bytes. These are in fact simply renamed EXE files, the original DOS kernel did not care for the file extension but only looked at the first 2 bytes to determine the file format (COM or EXE) of the program to be run.
References
- Wikipedia entry on COM files
- Entry on fileformat.info