The old DEBUG program can load COM files bigger than 64KB, but that doesn't mean they actually load as a program

Raymond Chen

Some times ago, I described why a corrupted binary sometimes results in the error “Program too big to fit in memory”. Commenter Neil was under the impression that nonrelocatable programs files could be larger than 64KB and used the DEBUG command to verify this assertion. While it’s true that DEBUG can load files bigger than 64KB, that doesn’t mean that they will load as a program. If DEBUG decide that you didn’t give it a program (the file extension is not EXE or COM),¹ then it treats the file on the command line as a data file and loads it into memory in its entirety, provided it fits in memory in its entirety. When it does this, the BX register contains the upper 16 bits of the file size, and CX contains the lower 16 bits. This is also the format that is used when writing files back out: Use the n command to set the name of the output file and set BX:CX to the file size. Even though DEBUG has been obsolete for over a decade, it is still useful for exactly this purpose: You can use it as a hex editor for files less than around 512KB. But don’t deceive yourself into thinking that you created a COM file that is bigger than 64KB.

¹There is another extension which has special meaning to DEBUG, but it’s not relevant to the discussion.