So What's a .COM Program, Exactly?

A .COM program is a DOS executable file format that is pure binary, as opposed to .EXE files most people are familiar with which contain a 32-byte header in front of them. One purpose of the header is to store relocation information to be able to switch between 64k segments. Since .COM programs do not have this information, they are limited to a 64k program size, while .EXE's can be much larger. In addition, Windows programs only use the .EXE file format.

If you could look directly at the bytes of a .COM file, the first set of bytes would correspond to the first assembly instruction. The instructions are read from the first byte and are followed consecutively (taking into account jumps, of course!) until the last instructions (which should be mov ax, 004c and int 21h) are found. I have written a bytereader program and sample .COM file so you can play around with them. Please realize that the code may contain bugs and I am not responsible for any damage occurring on anyone else's computer. (Download com.zip)

In addition, if you have the debug.com program you can use that by typing:

debug comfile.com
-d
will show you a hex dump of the file. (The '-' is the prompt)
-u
This will show you the instructions which these bytes represent.

Notice that the first time you type d or u, the offset is set to 100h. This leaves room for a 100h byte long Program Segment Prefix (PSP) which contains information about the file and some other data of mostly historical interest.

Return to NASM Tutorial