March 14th, 2011

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

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.

Topics
History

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.