Instructables

How to write the world's smallest "Hello World!" executable for PC

Ok, it may sound useless for modern PCs... but is amazing to watch how a 21 bytes .COM file can display text on screen. even on a 286 if you still have them :)
This guide will use "debug.exe", a nice app that comes after DOS 2.0 and you possibly have it on Windows folder if your running Windows OS. So, no need to download fancy assemblers or compilers.
I'll try to explain each step... but dont expect more that a text on screen...

A nice description about DEBUG.EXE can be found in...
http://mirror.href.com/thestarman/asm/debug/debug.htm
and http://en.wikipedia.org/wiki/DEBUG
hellow.zip639 bytes
 
Remove these adsRemove these ads by Signing Up

Step 1: Undestanding DEBUG.EXE

Our task should be creating a very small executable (in this case is a .COM file) in x86 assembly that should print "Hello World!" on the screen.

We will be using DEBUG.EXE that was released after DOS 2.0, it's mainly used to debug 16-bits applications.

You possibly have it on Windows System folder if your running Windows OS.
In Windows XP, it can be found in C:\WINDOWS\SYSTEM32\DEBUG.EXE

Enter in command-lines (I hope you know how to do this... if not, maybe this tutorial isn't good for you), first step should be calling DEBUG.EXE, since C:\WINDOWS\SYTEM32 is included in "PATH" enviroment, you can call it any path or drive:

C:\> debug.exe
-

You can type "?" then press ENTER to see the help.

(Again) A nice description about DEBUG.EXE can be found in...
http://mirror.href.com/thestarman/asm/debug/debug.htm
and http://en.wikipedia.org/wiki/DEBUG
hellow.zip639 bytes
Metalbrain8 years ago
You can cut one more byte replacing MOV AH, 09h with XCHG AX,BP
JustBurn (author)  Metalbrain7 years ago
There's guarantee that before the COM file is executed the register BP holds value 0x0009 ? If not, some unexpected things may happens (or a crash)... A lot of different versions of DOS OS exist (The most common ones now are MS-DOS), so probably shouldn't trust that general registers are initialized all the same between different versions of DOS. Also if I'm not wrong, only SP, DS, ES, SS, CS and IP are initialized, the rest is expected to be random (Remember I'm talking about 286 registers).
mh76dk JustBurn2 years ago
You can make it faster (cpu-cycle wise) using XOR AX,AX instead of MOV AX,0
mh76dk mh76dk2 years ago
Sorry, that should be XOR DX,DX but im sure you get my point :)
mh76dk mh76dk2 years ago
two more points: MOV AH, 0x09 leaves you with undefined AL (or maybe im not seeing where you zero out AL. secondly - holy lateness batman, didnt notice how old this instructable was untill just now :)
dahdash5 years ago
Thanks!
N3kk3tsu5 years ago
I liked it very much! Where can i find more tutorials and examples about Debug.exe? Where can i find more of your tutorials? Thank you!
JustBurn (author)  N3kk3tsu5 years ago
Thanks! You can google or check the wikipedia: http://en.wikipedia.org/wiki/DEBUG
If you want to play around with x86 assembly, I'll recommend:
NASM, best for 16-Bits DOS: http://www.nasm.us/
MASM32, best for 32-Bits WIN: http://www.masm32.com/
They are both free.

Thank you so much ;D
dx3406 years ago
try this:

@Echo Off
msg * Hello World
pause

=)
JustBurn (author)  dx3405 years ago
nice! although message service only work on Win2K based OS.. but still fun to do some interesting pop-up messages with batching :)
duct tape7 years ago
most assemblers have some quality of code checking to make sure that the code doesn't do much other than intended. Debug however, does not. This makes it dangerous to use to much, as I learned first hand a while ago. I was doing something like this, and I typed in the wrong register. When I ran it, garbage characters spewed across the screen and made a very annoying sound. It was even more annoying that you couldn't close out the program without shutting off the computer. Of course, the next day I loaded it into my bro's computer and changed the registry to start it on boot. ;)
Bolicao7 years ago
Hello World! I liked it! :) Could ne1 explain me how to ask for two numbers and sum them using windows xp debuger? Thank you
aceman 5697 years ago
I didn't understand a thing you said in this instructable.... :'(
mikesty8 years ago
echo Hello World! ;) Pretty neat stuff though. You know quite a bit about this :)
JustBurn (author)  mikesty8 years ago
Thank's :D I just love this kind of hardcore stuff, it remind me when had my 286 PC and lost hours messing with the system, playing EGA/VGA games and getting my nerves to make some programs to work because didn't had enough free convensional memory (640K!)... oh, "hellow.bat": @echo Hello World! 18 Bytes! But .BAT is basically like scripting, not real machine-code :P The "@" character avoid the command to be echoed, btw.
Bahaha, did gates not once say, "No one will ever need more than 640K!" or something like that?
Mz3FRS mikesty8 years ago
HAHA-back in the day, trying to configure your system to free up more conventional memory was half the fun of playing games! nearly makes me miss DOS.
mark101 Mz3FRS7 years ago
when did you pick that picture of "Cosmo Kramer" as an avatar?
for those who haven't seen the N-bomb http://www.friedbrains.com/video35.htm
JustBurn (author)  mikesty8 years ago
"640K ought to be enough for anybody.", but Bill Gates deny that actually said this. :)

http://en.wikiquote.org/wiki/Bill_Gates
Mr.Devious7 years ago
I made a dos executable a couple years back. It was a nasty hd bomber. Wiped a few people's drives with it, they pissed me off.
JustBurn (author)  Mr.Devious7 years ago
Now that's a guy that no one should piss him off. =P

Releasing virus is a serious crime now, i remember the case of the "ILoveYou" virus, the programmer were a woman, she got caught and sent to jail.

For my point of view, the HDD Bombers (Destroy file-system) and/or some BIOS ones(Make the PC un-bootable anymore without a BIOS reflash) were always the most scary type of virus to me.
Yea that would scare me. And it wasn't exactly a hd bomber, but it did just that. I wanted to test it to see if it worked and all it was somewhat simple format command and it wrecked the guys hd because it was too late when he canceled it. I'm not out to wreck people's computers nor am I a hacker. I was just a nasty little shit back then :-P
Delta6298 years ago
Cool, I haven't seen debug used since the late '80s.