COM file

from Wikipedia, the free encyclopedia

A COM file is an executable file in CP / M , MS-DOS and MS-DOS compatible operating systems . The name is derived from the file extension from ".COM", which for the English word command ( " command is").

Many Shell Tools such as the MS-DOS version of moreuse this format as well as small, early applications like the game Alley Cat by IBM .

Binary format

The COM format is perhaps the simplest format for executable files; it does not contain any metadata - only code and data - and is loaded and executed at offset 0x0100 of a segment. Due to the way in which the segmentation model works, no relocation is necessary.

However, simplicity comes at a price: the files are limited to a maximum size of 65,280 (0xFF00) bytes and store code and data in a single segment. This was not a problem on 8-bit architectures , but it is the main reason why the format will soon be phased out after the introduction of 16-bit architectures and later 32-bit and 64-bit architectures with their much larger segmented memories Fashion came and is uncommon today.

CP / M-80

Only 65,536 bytes of memory can be addressed on the Intel 8080 CPU architectures typical for CP / M-80 (address range 0x0000 to 0xFFFF). CP / M reserves the first page of this memory (0x0000 to 0x00FF) for the system, and an application program must be loaded exactly at address 0x0100 in order to be executed. COM files are perfect for this model. It is not possible to run more than one program or instruction at the same time; only the program loaded at 0x0100 is executed.

If the first byte of a CP / M-COM file is 0xC9, this indicates the presence of a 256-byte header for the CP / M 3. Since 0xC9 is the 8080 command for return , the COM file will terminate immediately if it is run on an earlier version of CP / M that does not support this extension.


On an Intel 8086 architecture required for MS-DOS , 1,024  KiB RAM can be addressed directly; Each segment address (0x0000 to 0xFFFF) allows access to a 64 KiB section of the memory (see memory segmentation of the 8086 processor ). The COM files are loaded into any free segment from offset 0x0100. The operating system uses the 256 bytes at the beginning of the segment for the Program Segment Prefix (PSP). Several programs can be loaded at the same time; However, since DOS is a single-tasking system, the programs are executed in a nested manner, with the higher-level program only being continued after the lower-level program has ended. Only special TSR programs alternate, so to speak, with the last program started.

The file name extension ".COM" is sometimes used under MS-DOS for MZ files that are actually incorrectly named . Examples of such files are the programs COMMAND.COM and EDIT.COM in some DOS versions. MZ files usually have the ".EXE" extension (Engl. Executable , executable); DOS ignores the filenames used and differentiates the two formats by the magic number of MZ files.

Exchange of both formats

The similarities between COM files under CP / M-80 and MSDOS are exhausted with the same load address 100h and the position of the command line when the program is called (80h ... FFh). There are no similarities in the machine code, the interface to the operating system or the output of characters on the screen. Disk formats were still incompatible, mostly at the hardware level. Fat COM files were not supported and were not an issue at the time.

Platform support

CP / M-80 programs cannot be run natively under MS-DOS. The DOS system below is used under Windows up to Windows 9x . 32-bit Windows NT systems cannot run DOS programs natively, but only with the help of the Virtual DOS Machine . The 64-bit Windows versions lack this layer, which is why alternative emulators such as DOSBox must be used. OS / 2 also used an emulation layer.

Priority in execution

If both a COM and an EXE file with the same name are found in a folder, COMMAND.COM from MS-DOS (or compatible) prefers the COM file. If the execution of the EXE file is required, this can be explicitly enforced from MS-DOS Version 4.00 by specifying the entire file name with the extension. (Example: If both a FOO.COM and a FOO.EXE are in the current directory , the command starts FOOthe COM file and only FOO.EXEthe EXE file).

Computer viruses are sometimes spread by taking advantage of this behavior. The virus is placed in files with names such as MEM.COM. It is then speculated that - placed in the same folder as a corresponding EXE file - the user will MEMexecute the virus with the shorter command , without an extension, instead of the original MEM.EXE (program for memory display contained in MS-DOS).


Computer virus programmers also take advantage of the fact that .com is now associated with the top-level domain of the same name by calling their programs www. (…) .Com. If such a file is sent as an e-mail, the inexperienced Windows user is shown a domain according to the pattern, who, contrary to his expectations, does not (or not only) www.example.comopen the page , but rather executes the file www.examplewith the extension .com.

Individual evidence

  1. Microsoft KB35284: Order of Precedence in Locating Executable Files (English)