如何制作 MSDOS .com 文件?
如何为 MS-DOS 制作 .com 文件?我有自己的“操作系统”PowerOS,并且我希望能够输入自定义命令。有什么办法可以写一个.com文件吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案相当简单。通过用编程语言编写程序并使用面向 MS/PC/DR-DOS 的编译器进行编译,可以创建包含 MS/PC/DR-DOS 程序映像的
.COM
文件。就是这样。不要对文件扩展名感到困惑。有一个
.COM
程序映像文件格式,这是一种相当基本的程序映像格式。它在 20 世纪 80 年代被“MZ”程序图像文件格式取代。但这与文件扩展名无关。 MS/PC/DR-DOS 的程序映像文件可以具有扩展名.COM
或扩展名.EXE
,但实际的映像文件格式 不是由这个决定的。 (我提到了 DR-DOS。如果内存正常的话:在 DR-DOS 版本 6 中,几乎所有程序映像文件,甚至是名为.COM
的文件,实际上都是“MZ”格式的可执行文件,并且经过压缩)您所做的事情取决于操作系统的程序加载器能够理解的程序映像文件格式。事实上,只有你可以告诉世界这一点。如果您的操作系统的程序加载器能够理解“MZ”可执行文件格式,并且您的操作系统上运行的程序是16位且以实模式运行,那么为您的操作系统编译命令就很简单(忽略系统调用和库)问题),比如启动 OpenWatcom 的 16 位编译器+链接器,
wcl
,并使用-bcl=DOS
选项告诉它以 MS/PC/DR-DOS 为目标。当然,如果您的程序是32位并且您的操作系统在保护模式下运行它们,或者即使您的程序是16位并且您的操作系统在保护模式下运行它们,那么“MZ”文件格式将不适合您的需要,您应该使用 以下几个之一替代程序映像文件格式。
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.
我知道对于 Windows 7 以及很可能对于其他 Windows 操作系统,您可以编写 .bat、.exe 或 .com 并将其放入 windows/system32 文件夹中。只需键入您创建的命令的名称,即可将该文件用作命令提示符下的命令。
要获取命令行参数,批处理文件可以使用变量 %1、%2、%3 等。该命令的工作方式与任何其他命令类似,可用于进一步写入批处理文件。
就 MS-DOS 而言,您可以将这些文件类型之一放置在根目录中,或者找到放置其他命令的位置并将其放在那里。我不确定是否需要 COM 文件,但如果需要,则有批处理到 com 转换器,例如这个老式的转换器:
从批处理转换为 com
I know that for windows 7 and most likely for the other windows OS's you can write either a .bat, .exe, or .com and place it into windows/system32 folder. That file can be used as a command from the command prompt by simply typing in the name of the command you made.
To take in command line parameters, a batch file can use the variables %1, %2, %3 etc. The command works like any other command and can be used to further write batch files with it.
As far as MS-DOS goes, you may be able to place one of those file types in the root directory or find where the other commands are placed and put it there. I am not sure if a COM file is required, but if so, there are batch to com converters out there such as this old school one:
Converter from batch to com