All Topics  
COM file

 

   Email Print
   Bookmark   Link






 

COM file



 
 
In many computer operating systems, a COM file is a type of executable file
Executable

In computing, an executable causes a computer "to perform indicated tasks according to encoded instruction ," as opposed to a file that only contains data ....
; the name is derived from the file name extension .COM. Originally, the term stood for "Command file", a text file containing commands to be issued to the operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 (similar to a DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 batch file
Batch file

In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of Command intended to be executed by the Command line interpreter....
), on many of the Digital Equipment Corporation
Digital Equipment Corporation

Digital Equipment Corporation was a pioneering United States company in the computer industry. It is often referred to within the computing industry as DEC ....
 mini
Minicomputer

A minicomputer is a class of multi-user computers that lies in the middle range of the computing spectrum, in between the largest multi-user systems and the smallest single-user systems ....
 and mainframe
Mainframe

Mainframe may refer to one of the following:* Mainframe computer, large data processing systems* Mainframe Entertainment, a Canadian computer animation and design company....
 operating systems going back to the 1970s.

With the introduction of microcomputer
Microcomputer

A microcomputer is a computer with a microprocessor as its central processing unit. Another general characteristic of these computers is that they occupy physically small amounts of space when compared to mainframe computer and minicomputers....
s, the type of files commonly associated with the extension .com changed; in 8-bit
8-bit

Eight-bit CPUs normally use an 8-bit data bus and a 16-bit address bus which means that their address space is limited to 64 KBs. This is not a "natural law", however, so there are exceptions....
 CP/M
CP/M

CP/M is an operating system originally created for Intel 8080/Intel 8085 based microcomputers by Gary Kildall of Digital Research. Initially confined to single tasking on 8-bit processors and no more than 64 kilobytes of memory, later versions of CP/M added multi-user variations, and were migrated to 16-bit processors....
, and later in MS-DOS
MS-DOS

MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
 and compatible DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
es, they are binary
Binary file

A binary file is a computer file which may contain any type of data, encoded in Binary numeral system form for computer storage and processing purposes; for example, Document file format containing formatted text....
 executable files by convention.






Discussion
Ask a question about 'COM file'
Start a new discussion about 'COM file'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In many computer operating systems, a COM file is a type of executable file
Executable

In computing, an executable causes a computer "to perform indicated tasks according to encoded instruction ," as opposed to a file that only contains data ....
; the name is derived from the file name extension .COM. Originally, the term stood for "Command file", a text file containing commands to be issued to the operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 (similar to a DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 batch file
Batch file

In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of Command intended to be executed by the Command line interpreter....
), on many of the Digital Equipment Corporation
Digital Equipment Corporation

Digital Equipment Corporation was a pioneering United States company in the computer industry. It is often referred to within the computing industry as DEC ....
 mini
Minicomputer

A minicomputer is a class of multi-user computers that lies in the middle range of the computing spectrum, in between the largest multi-user systems and the smallest single-user systems ....
 and mainframe
Mainframe

Mainframe may refer to one of the following:* Mainframe computer, large data processing systems* Mainframe Entertainment, a Canadian computer animation and design company....
 operating systems going back to the 1970s.

With the introduction of microcomputer
Microcomputer

A microcomputer is a computer with a microprocessor as its central processing unit. Another general characteristic of these computers is that they occupy physically small amounts of space when compared to mainframe computer and minicomputers....
s, the type of files commonly associated with the extension .com changed; in 8-bit
8-bit

Eight-bit CPUs normally use an 8-bit data bus and a 16-bit address bus which means that their address space is limited to 64 KBs. This is not a "natural law", however, so there are exceptions....
 CP/M
CP/M

CP/M is an operating system originally created for Intel 8080/Intel 8085 based microcomputers by Gary Kildall of Digital Research. Initially confined to single tasking on 8-bit processors and no more than 64 kilobytes of memory, later versions of CP/M added multi-user variations, and were migrated to 16-bit processors....
, and later in MS-DOS
MS-DOS

MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
 and compatible DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
es, they are binary
Binary file

A binary file is a computer file which may contain any type of data, encoded in Binary numeral system form for computer storage and processing purposes; for example, Document file format containing formatted text....
 executable files by convention. However, executables in the COM file format
File format

A file format is a particular way to encode information for storage in a computer file.Since a disk drive, or indeed any computer storage, can store only bits, the computer must have some way of converting information to 0s and 1s and vice-versa....
 do not have to have the file name extension .COM in any but CP/M and very early versions of MS-DOS.

The .COM file name extension has no relation to the .com
.com

.com is a generic top-level domain used on the Internet's Domain Name System. It was one of the original top-level domains , established in January 1985, and has grown to be the largest TLD in use....
 (for "commercial") top-level Internet domain name. However, this similarity in name has been exploited by malicious computer virus writers.

MS-DOS binary format

The COM format is the original binary executable format used in CP/M and MS-DOS. It is very simple; it has no header, and contains no metadata
Metadata

Metadata is "data about other data", of any sort in any media. An item of metadata may describe an individual datum, or content item, or a collection of data including multiple content items and hierarchical levels, for example a database schema....
, only code and data. Its simplicity exacts a price, however: the binary has a maximum size of 65,280 (0xFF00) bytes (a little bit less than 64 KiB) and stores all its code
Code segment

In computing, a code segment, also known as a text segment or simply as text, is a phrase used to refer to a portion of memory or of an object file that contains executable Instruction s....
 and data
Data segment

A data segment is one of the sections of a program in an object file or in memory, which contains the global variables that are initialized by the programmer....
 in one segment.

Since it lacks relocation information, it is loaded
Loader (computing)

In computing, a loader is the part of an operating system that is responsible for loading programs from executables into memory, preparing them for execution and then executing them....
 by the operating system at a pre-set address, at offset 0x
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
0100, where it is executed. This was not an issue on early 8-bit
8-bit

Eight-bit CPUs normally use an 8-bit data bus and a 16-bit address bus which means that their address space is limited to 64 KBs. This is not a "natural law", however, so there are exceptions....
 machines because of how the segmentation model works, but it is the main reason why the format fell into disuse soon after the introduction of 16-
16-bit

16-bit architectureThe HP 2100#Descendants and variants , introduced in 1975, was the world's first 16-bit microprocessor.Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816....
 and then 32-bit
32-bit

The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295 or -2,147,483,648 through 2,147,483,647 using two's complement encoding....
 processors with their much larger, segmented
Memory segment

x86 memory segmentation refers to the implementation of memory segmentation on the x86 architecture. Memory is divided into portions that may be addressed by a single index register without changing a 16-bit segment selector....
 memories.

In the Intel 8080
Intel 8080

The Intel 8080 was an early microprocessor designed and manufactured by Intel. The 8-bit microprocessor was released in April 1974 running at 2 megahertz , and is generally considered to be the first truly usable microprocessor....
 CPU architecture, only 65,536 bytes of memory could be addressed (address range 0x0000 to 0xFFFF). Under CP/M, the first page of this memory, from 0x0000 to 0x00FF was reserved for system use, and any user program had to be loaded at exactly 0x0100 to be executed. COM files fit this model perfectly. Note that there was no possibility of running more than one program or command at a time: the program loaded at 0x0100 was run, and no other.

Although the file format is the same in MS-DOS and CP/M, this does not mean that CP/M programs can be directly executed under MS-DOS or vice versa; MS-DOS COM files contain x86 instructions, while CP/M COM files contain 8080
Intel 8080

The Intel 8080 was an early microprocessor designed and manufactured by Intel. The 8-bit microprocessor was released in April 1974 running at 2 megahertz , and is generally considered to be the first truly usable microprocessor....
, 8085
Intel 8085

The Intel 8085 is an 8-bit microprocessor introduced by Intel in 1977. It was binary-compatible with the more-famous Intel 8080 but required less supporting hardware, thus allowing simpler and less expensive microcomputer systems to be built....
 or Z80
Zilog Z80

The Zilog Z80 is an 8-bit microprocessor designed and sold by Zilog from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes....
 instructions. Additionally, MS-DOS COM files often depend on operating system traps
Trap (computing)

In computing and operating systems, a trap is a type of synchronization interrupt typically caused by an exception handling condition in a user process ....
 supplied exclusively by MS-DOS via interrupt 21h
BIOS interrupt call

BIOS Interrupt Calls are a facility that DOS programs, and some other software such as boot loaders, use to invoke the BIOS's facilities. Some operating systems also use the BIOS to probe and initialise hardware resources during their early stages of booting....
. It is possible to construct a fat
Fat binary

A fat binary is a computer program that is native to multiple Instruction set and thus can be run on multiple processor types. The usual method of implementation is to include a version of the machine code for each ISA, resulting in a file larger than a normal one-architecture binary, thus the name....
 COM file which both processor families can execute.

Under CP/M 3, if the first byte of a COM file is 0xC9 then this indicates the presence of a 256-byte header; since 0xC9 corresponds to the 8080
Intel 8080

The Intel 8080 was an early microprocessor designed and manufactured by Intel. The 8-bit microprocessor was released in April 1974 running at 2 megahertz , and is generally considered to be the first truly usable microprocessor....
 instruction RET, this means that the COM file will immediately terminate if run on an earlier version of CP/M that does not support this extension.

Files may have names ending in .COM, but not be in the simple format described above; this is indicated by a magic number
Magic number (programming)

In computer programming, the term magic number has multiple meanings. It could refer to one or more of the following:* a constant used to identify a file format or protocol;...
 at the start of the file. For example, the COMMAND.COM
COMMAND.COM

COMMAND.COM is the filename of the default operating system Shell for DOS operating systems and the default command line interpreter on 16/32-bit versions of Microsoft Windows ....
 file in DR-DOS
DR-DOS

DR-DOS is a DOS-type operating system for IBM PC-PC compatible personal computers, originally developed by Gary Kildall's Digital Research and derived from CP/M-86....
 6 is actually in DOS executable
DOS executable

The DOS MZ executable format is the executable file format used for EXE files in DOS.The file can be identified by the ASCII string "MZ" or the hexadecimal 4D 5A at the beginning of the file ....
 format, indicated by the first two bytes being MZ (0x4D 0x5A), the initials of Mark Zbikowski
Mark Zbikowski

Mark Zbikowski is a former Microsoft Architect and an early computer Hacker . He started working at the company only a few years after its inception, leading efforts in MS-DOS, OS/2, Cairo and Windows NT....
.

Large programs

In MS-DOS
MS-DOS

MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
 and compatible DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
es, there is no memory management
Memory management

Memory management is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed....
 provided for COM files by the loader
Loader (computing)

In computing, a loader is the part of an operating system that is responsible for loading programs from executables into memory, preparing them for execution and then executing them....
 or execution environment. All memory is simply available to the COM file. After execution, the operating system command shell, COMMAND.COM
COMMAND.COM

COMMAND.COM is the filename of the default operating system Shell for DOS operating systems and the default command line interpreter on 16/32-bit versions of Microsoft Windows ....
, is reloaded. This leaves the possibilities that the COM file can either be very simple, using a single segment, or arbitrarily complex, providing its own memory management system. An example of a complex program would be COMMAND.COM, the MS-DOS shell, which provided a loader to load other COM or EXE
EXE

EXE is the common filename extension denoting an executable file in the DOS, OpenVMS, Microsoft Windows, ReactOS, and OS/2 operating systems.Besides the executable program itself, many EXE files contain other components called Resource , such as bitmaps and icons which the executable program may use for its graphical user interface....
 programs. In the .COM system, larger programs (up to the available memory size) can be loaded and run, but the system loader assumes that all code and data is in the first segment, and it is up to the .COM program to provide any further organization. Programs larger than available memory, or large data segment
Data segment

A data segment is one of the sections of a program in an object file or in memory, which contains the global variables that are initialized by the programmer....
s, can be handled by dynamic linking, if the necessary code is included in the .COM program. The advantage of using a .COM rather than a .EXE format is that the binary image is usually smaller and easier to program using an assembler
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
. Once compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
s and linker
Linker

In computer science, a linker or link editor is a computer program that takes one ormore object file generated by a compiler and combines them into a single executable program....
s of sufficient power became available it was no longer advantageous to use the .COM format for complex programs.

Execution preference

In MS-DOS, if a directory contains both a COM file and an EXE
EXE

EXE is the common filename extension denoting an executable file in the DOS, OpenVMS, Microsoft Windows, ReactOS, and OS/2 operating systems.Besides the executable program itself, many EXE files contain other components called Resource , such as bitmaps and icons which the executable program may use for its graphical user interface....
 file with same name (not including extension), the COM file is preferred. For example, if a directory in the system path
Path (variable)

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of Directory where executable programs are located....
 contains two files named foo.com and foo.exe, the following would execute foo.com:

C:\>foo

If the user wishes to run foo.exe, they can explicitly use the complete filename:

C:\>foo.exe

Taking advantage of this default behaviour, virus
Computer virus

A computer virus is a computer program that can copy itself and infect a computer without the permission or knowledge of the user. The term "virus" is also commonly but erroneously used to refer to other types of malware, adware and spyware programs that do not have the reproductive ability....
 writers and other malicious programmers sometimes use names like notepad.com for their creations, hoping that if it is placed in the directory of the corresponding EXE file, a run command or batch file may accidentally trigger their program instead of the ubiquitous notepad.exe
Notepad

Notepad is a simple text editor included in all versions of Microsoft Windows since Windows 1.0 in 1985....
 text editor.

On Windows NT
Windows NT

Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was originally designed to be a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix....
 and derivatives (Windows 2000
Windows 2000

Windows 2000 is a line of operating systems produced by Microsoft for use on business desktops, Laptop, and Server . Released on 17 February, 2000, it was the successor to Windows NT 4.0, and is the final release of Microsoft Windows to display the "Windows NT" designation....
, Windows XP
Windows XP

Windows XP is a line of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptop, and media centers....
, and Windows Vista
Windows Vista

Windows Vista is one member in a family of operating systems developed by Microsoft for use on personal computers, including home and business Desktop computer, laptops, Tablet PCs, and media center PCs....
), the PATHEXT variable is used to determine the order of preference (and acceptable extensions) for calling files without specifying the extension from the command line. The default value still places .com files before .exe files.

Platform support

The format is still executable
Executable

In computing, an executable causes a computer "to perform indicated tasks according to encoded instruction ," as opposed to a file that only contains data ....
 on many modern Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
-based platforms
Platform (computing)

In computing, a platform describes some sort of hardware architecture or software framework , that allows Computer software to run. Typical platforms include a computer's Computer architecture, operating system, programming languages and related runtime libraries or graphical user interface....
, but it is run in an MS-DOS-emulating subsystem, NTVDM
Virtual DOS machine

Virtual DOS machine is Microsoft's technology that allows running legacy MS-DOS and Windows 3.1x programs on Intel 80386 or higher computers when there is already another operating system running and controlling the hardware....
, which is not present in 64-bit
64-bit

64-bit CPUs have existed in supercomputers since the 1960s and in RISC-based computer workstation and Server s since the early 1990s. In 2003 they were introduced to the mainstream personal computer arena, in the form of the x86-64 and 64-bit PowerPC processor architectures....
 variants. COM files can also be executed on DOS emulators such as DOSBox
DOSBox

DOSBox is an emulator which emulates an IBM PC compatible computer running MS-DOS. It is intended especially for use with old Personal computer game....
, on any platform supported by these emulators.

Malicious usage of the .com extension

Some computer virus writers have hoped to take advantage of modern computer users' likely lack of knowledge of the .com file extension and associated binary format, along with their more likely familiarity with the .com
.com

.com is a generic top-level domain used on the Internet's Domain Name System. It was one of the original top-level domains , established in January 1985, and has grown to be the largest TLD in use....
 Internet domain name. E-mail has been sent with attachment names similar to "www.example.com". Unwary Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 users clicking on such an attachment would expect to begin browsing a site named http://www.example.com/, but instead would run the attached binary command file named www.example, giving it full permission to do to their machine whatever its author had in mind.

Note that there is nothing malicious about the COM file format itself; this is an exploitation of the coincidental name collision between .com command files and .com commercial web sites.

See also

  • MS-DOS API
    MS-DOS API

    The MS-DOS API is an API used originally in MS-DOS/PC-DOS, and later by other DOS systems. Most calls to the DOS API invoke software interrupt 21h ....