Source debugging COM files with Turbo Debugger

Borland TASM team never liked the idea of COM files, no wonder since Microsoft eventually said it will kill the format with never DOS releases. That never happened but generating and debugging 16-bit DOS EXE executables with TASM is easy. Doing the same in case of COM files is a bit more tricky and not well documented.

Building 16-bit DOS EXE files with TASM and TLINK to support source level debugging is straightforward:

TASM /zi filename.asm
TLINK /v filename.obj

It seems that doing the same in case of COM file should be just a matter of adding /t switch to TLINK command line. Try it if you like but this approach will fail.

How to solve this problem? It turns out we need to use third tool to achieve our goal. We need to use TDSTRIP to generate COM file out of EXE file:

TASM /zi filename.asm
TLINK /v filename.obj
TDSTRIP -s -c filename.exe filename.com

Now you can use Turbo Debugger and have a source level debugging enabled.

Keep in mind that in order to create COM file out of EXE you need to follow server guidelines:

  1. Use TINY memory model
  2. The size of executable can not exceed single segment (64kb)
  3. All calls and label must be NEAR
  4. Set entry point offset to 100h, the STARTUPCODE directive takes care for you automatically when TINY memory model has been used
  5. You can’t have a predefined stack segment

If you are using STARTUPCODE directive you may wonder about using EXITCODE directive as well. In case of COM files the EXITCODE directive generates simple int 21h function 4Ch call. As a side note the example COM file template COMPROG.ASM from EXAMPLE\USRGUIDE directory does not use EXITCODE, but simple: mov ah,4ch / int 21h.

5 thoughts on “Source debugging COM files with Turbo Debugger

  1. Trixter

    I can’t believe this has existed for this long and I missed it. I was always under the impression that there was no way to symbolically debug .COM files. I just tried it and it worked! Thank you for posting this!

    Like

    Reply
    1. ACP Post author

      You are welcome. Glad this small blog still is useful after all those years. I’m glad even more that there are people around who actually have been using all those debugging tools back in 80’s and early 90’s – those were awesome times.

      Like

      Reply
  2. ACP Post author

    It is great fun even today indeed. Still my debugger of choice has been Periscope and SoftICE. COM file format isn’t that bad as some think. Its simplicity is the key advantage assuming you can fit your code. DOS 16bit MZ EXE is more complex and maybe an overkill for smaller projects. Writing a small TSR is great example: make is a simple COM file and forget about segments and memory models, counting the number of paragraphs is also trivial.

    Like

    Reply
  3. Trixter

    So, if you’re curious what I was working on that this information helped with, look up “Area 5150” “demoscene” and you’ll hopefully be pleased 🙂

    Like

    Reply

Leave a comment