Sometimes you get the urge to do some programming, but you don’t have access to a compiler. Luckily, virtually every Windows PC in the world has a utility called “debug” installed. This little program lets you input 16-bit x86 assembly language, and allows you to write it out to create a .com file. This file can then be executed inside of a DOS shell.
The following is an example of something simple but cool you can do with this program. I will be using some basic DOS interrupts in order to do console input and output. (Lookup ‘DOS interrupt 21h’ on google to find out more).
I’ll highlight everything i’m typing in green so you can try this at home. You won’t need to type the optional comments (anything after the semicolon is ignored), and they get lost when you write the file anyway.
C:>debug kthx.com -a 100 1476:0100 mov cl, d7 ; default cl to character 'd7' 1476:0102 mov ah, 6 ; ah:6 is console input/output 1476:0104 mov dl, ff ; dl:ff specifies input 1476:0106 int 21 ; interrupt 21 call 1476:0108 jz 10c ; skip next instruction if failure 1476:010A mov cl, al ; save result of console input 1476:010C mov dl, cl ; load current character as output 1476:010E int 21 ; interrupt 21 call 1476:0110 jmp 102 ; loop forever! 1476:0112 -r cx CX 0012 :12 -w Writing 00012 bytes -q C:>
Now, when you execute “kthx.com”, you will see the screen swamped with the funky ‘d7’ ASCII character.
Whenever you type a character, the screen with update to display that character. Try alternating between visible characters and not visible characters (like space). For more fun, try to as quickly as possible type “|/-|/-” (animates like a little progress bar).
Note that you cant really exit the program. Pressing ctrl+c will actually just display a little heart character. It would be easy to modify the code to accept a character (like escape or control+c) to exit, but i’ll leave that up to you :].
This is just one basic thing you can make a .com file do. For a cooler example, check out neetro. Neetro is a little bit more complex than the program above, so it would have been a pain to write using “debug”. The source is instead compiled using nasm.
2 thoughts on “DOS “debug” fun”
It’s a shame people don’t use their memory as efficiently as possible , these days they throw with gigabytes as if it’s a number instead of the content of a whole library of books.
and the tendency to actually make things as slow as possible so people can have a reason to buy a new computer every year is something worth taking out the banner on a stick for , and stand in front of … well nowhere really… i’n sure they invented java just for that reason.
Quite often i find myself wondering what could be achieved with the hardware in my computer if someone would chose the low level approach , and write something in cpu and gpu assembly for the specific pieces of hardware. yes it would take an astronomical amount of time to do , and yes it would only run on a few computers , but we could at least shove it in the current developer’s faces and show them what level of performance we actually expect from their software .
I wish i could send one of these computers , including low level manuals back in time to the 8 bit or 16 bit period , and have the guys that were going to change the world (and now wear dark blue suits) have a go at it.