Search code examples
x86executabledosx86-16executable-format

can a .com executable run on other OS besides windows?


I understand that the extension of the executables .com .exe etc is meant for the operating system. It has got nothing to do with the underlying ISA (be it x86 or SPARC). Am I correct? does .com executable run only on windows OS ? Are .com executables legacy?


Solution

  • The .com, .exe extension tells the DOS or Windows operating systems that the file is an executable. The file extension (.com, .exe) alone doesn't tell the operating system what the underlying instruction set is. For Windows executables with a .exe extension the instruction set is specified in the first few bytes of the file (the PE header).

    Originally DOS .com files simply contained a set of instructions that the operating system (i.e. DOS) would load at a fixed address and execute from the first instruction. These type of .com files are 'legacy'. They cannot be run on modern operating systems without emulation. This type of .com files can be found on CP/M and later (and more commonly) DOS but only run on the operating system and instruction architecture they were originally designed for. You can run them on other operating systems through emulation. e.g. dosbox runs DOS .com files on Linux. Later versions of DOS and then Windows look inside .com files to see if they are really LE/PE executables. If they are it executes them as if they had a .exe extension instead. Visual Studio ships some files with the .com extension. See https://devblogs.microsoft.com/oldnewthing/20080324-00/?p=23033 for more on this.