user9131762
user9131762

Reputation:

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

I'm working on a kernel based on Assembly x86 programming language. I just wondered what is the difference between .bin files and .com files. Can I boot from a .com file? Where and how to use .com files?

Upvotes: 0

Views: 453

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62048

If you're talking about DOS executables, then a .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, which includes the command line with arguments.

There's no generally agreed-on structure of a .BIN file. It can be anything. DOS doesn't recognize it.

The BIOS (unless we're talking about UEFI) doesn't support any executable format. It just loads the very first sector from the disk (to physical address 0x7C00) and passes control to it (setting CS:IP to either 0:0x7C00 or 0x7C0:0). The sector must be able to load (using BIOS int 0x13) more sectors from the disk somehow.

IOW, the BIOS generally can't load a whole .COM program and successfully start it. Even for such a simple task one would need a first stage boot loader. But it can be done. See e.g. my BootProg. It can load DOS .COMs and .EXEs.

Upvotes: 5

Related Questions