Search code examples
operating-systemcommanddos

How do you make a MSDOS .com file?


How do you make a .com file for MS-DOS? I have my own "operating system", PowerOS, and I want custom commands to be able to be entered. Is there any way to write a .com file?


Solution

  • The answer is fairly straightforward. You make a .COM file containing an MS/PC/DR-DOS program image by writing a program in a programming language and compiling it with a compiler that targets MS/PC/DR-DOS. That's it.

    Don't get confused about filename extensions. There's a .COM program image file format, which is a fairly basic program image format. It was superseded by the "MZ" program image file format back in the 1980s. But it has nothing to do with the filename extension. A program image file for MS/PC/DR-DOS can have either the extension .COM or the extension .EXE, but the actual image file format is not dictated by this. (I mention DR-DOS. If memory serves correctly: In DR-DOS version 6 practically all of the program image files, even the ones named .COM, were actually "MZ" format executables, and compressed ones at that.)

    What you do depends from what program image file formats your operating system's program loader is capable of understanding. And, really, only you can tell the world that. If your operating system's program loader understands the "MZ" executable file format, and the programs that run on your operating system are 16-bit and run in real mode, then compiling commands for your operating system is as simple (ignoring system call and library issues) as, say, cranking up OpenWatcom's 16-bit compiler+linker, wcl, and telling it to target MS/PC/DR-DOS with the -bcl=DOS option.

    Of course, if your programs are 32-bit and your operating system runs them in protected mode, or even if your programs are 16-bit and your operating system runs them in protected mode, then the "MZ" file format will be unsuitable for your needs, and you should use one of the several alternative program image file formats.