“.com”文件和“.bin”文件有什么区别?

What is the difference between a ".com" file and a ".bin" file?

我正在开发基于汇编 x86 编程语言的内核。我只是想知道 .bin 文件和 .com 文件有什么区别。我可以从 .com 文件启动吗?在哪里以及如何使用 .com 文件?

如果您谈论的是 DOS 可执行文件,那么 .COM file has very little structure. It's first byte corresponds to IP=0x100. When DOS starts it, it sets CS=DS=ES=SS=segment into which the file is loaded. IP is 0x100, SP is typically close to 0xFFFE (unless DOS is short of memory). The space between offset 0 and 0x100 has some control information, the Program Segment Prefix,其中包括带参数的命令行。

没有公认的 .BIN 文件结构。它可以是任何东西。 DOS 无法识别它。

BIOS(除非我们谈论的是 UEFI)不支持任何可执行格式。它只是从磁盘加载第一个扇区(到物理地址 0x7C00)并将控制权传递给它(将 CS:IP 设置为 0:0x7C00 或 0x7C0:0)。该扇区必须能够以某种方式从磁盘加载(使用 BIOS int 0x13)更多扇区。

IOW,BIOS 通常无法加载整个.COM 程序并成功启动它。即使是这样一个简单的任务,也需要一个第一阶段引导加载程序。但这是可以完成的。参见例如我的 BootProg。它可以加载 DOS .COM 和 .EXE。