DOS executable (.com)

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
m
Line 1: Line 1:
 
{{FormatInfo
 
{{FormatInfo
|subcat=Executables
+
| subcat = Executables
|extensions={{ext|com}}
+
| extensions = {{ext|com}}
|mimetypes=
+
{{mimetype|application/octet-stream}}
+
 
}}
 
}}
==Introduction==
+
'''COM''' ("command file") is the native executable format of [[wikipedia:CP/M|CP/M]]. The format was inherited by the DOS family of operating systems; MS-DOS 1.0 introduced [[MS-DOS EXE|MZ]] as a replacement. COM files are raw, flat binaries without relocations; there are no identifying headers or magic numbers, except for a variant introduced in CP/M 3 which contains a 256-byte header.
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 [[MS-DOS EXE|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 (<code>0x100</code>) 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 <code>0xe9</code> or <code>oxeb</code> 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.
+
On PC computers, COM files are loaded at fixed offset 0x100 in an arbitrary [[wikipedia:x86 memory segmentation#Real mode|real mode memory segment]]. The entry point is located at the start of the file. Many COM files start with a jump instruction (opcode <code>0xe9</code> or <code>0xeb</code>), but this isn't required. Since the executable is limited to a single segment, the maximum size of a COM file is 65280 (0xff00) bytes.
  
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 [[MS-DOS EXE|EXE]] files, the original DOS kernel did not care about 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.
+
Some files carrying the <code>.com</code> extension are in fact in the [[MS-DOS EXE|MZ]] format: for example, the <code>COMMAND.COM</code> and <code>EDIT.COM</code> binaries distributed with Windows 95 and later are MZ executables. The DOS loader can detect this and load the file appropriately.
  
==References==
+
== References ==
*[http://en.wikipedia.org/wiki/COM_file Wikipedia entry] on COM files
+
* [[Wikipedia: COM file]]
*[http://www.fileformat.info/format/com/corion.htm Entry] on fileformat.info
+
* [http://www.fileformat.info/format/com/corion.htm Entry] on fileformat.info
[[category:File formats with extension .com]]
+

Revision as of 18:56, 27 August 2015

File Format
Name DOS executable (.com)
Ontology
Extension(s) .com

COM ("command file") is the native executable format of CP/M. The format was inherited by the DOS family of operating systems; MS-DOS 1.0 introduced MZ as a replacement. COM files are raw, flat binaries without relocations; there are no identifying headers or magic numbers, except for a variant introduced in CP/M 3 which contains a 256-byte header.

On PC computers, COM files are loaded at fixed offset 0x100 in an arbitrary real mode memory segment. The entry point is located at the start of the file. Many COM files start with a jump instruction (opcode 0xe9 or 0xeb), but this isn't required. Since the executable is limited to a single segment, the maximum size of a COM file is 65280 (0xff00) bytes.

Some files carrying the .com extension are in fact in the MZ format: for example, the COMMAND.COM and EDIT.COM binaries distributed with Windows 95 and later are MZ executables. The DOS loader can detect this and load the file appropriately.

References

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox