What's the difference between .COM and .EXE formats?

No Comments
What's the difference between .COM and .EXE formats?

To oversimplify: a .COM file is a direct image of how the program will look in main memory, and a .EXE file will undergo some further relocation when it is run (and so it begins with a relocation header). A .COM file is limited to 64K for all segments combined, but a .EXE file can have as many segments as your linker will handle and be as large as RAM can take. The actual file extension doesn't matter. DOS knows that a file being loaded is in .EXE format if its first two bytes are MZ or ZM; otherwise it is assumed to be in .COM format. Actually they must be less than 0xFF00 bytes long, since the PSP, which isn't included in the COM file but is within those 64K, is 256 bytes long. Then CAN use many segments, but they don't have to. In particular, any .COM file can be converted to an .EXE file by adding an appropriate header to it. There are some other differences between a .COM file and a single segment .EXE file (both of which must be smaller than 64K).The entry point of the .COM file is _always_ 0x100, while the entry point of the .EXE file can be at any address. The stack size of the .COM file is the remainder of those 64K which isn't used by the code image, while the stack size if the single segment .EXE file can be set at any size as long as it fits within those 64K.Thus the stack can be smaller in the .EXE file.
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment