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

 by JustBurn
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
Metalbrain says: Aug 19, 2006. 4:59 PM
You can cut one more byte replacing MOV AH, 09h with XCHG AX,BP
JustBurn (author) in reply to MetalbrainJan 3, 2007. 6:06 PM
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 in reply to JustBurnJul 19, 2012. 12:35 PM
You can make it faster (cpu-cycle wise) using XOR AX,AX instead of MOV AX,0
mh76dk in reply to mh76dkJul 19, 2012. 12:40 PM
Sorry, that should be XOR DX,DX but im sure you get my point :)
mh76dk in reply to mh76dkJul 19, 2012. 12:53 PM
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 :)
dahdash says: Dec 22, 2008. 5:36 PM
Thanks!
N3kk3tsu says: Oct 21, 2008. 5:00 PM
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) in reply to N3kk3tsuOct 22, 2008. 7:45 PM
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.

N3kk3tsu in reply to JustBurnOct 23, 2008. 12:00 AM
Thank you so much ;D
dx340 says: May 10, 2008. 2:15 AM
try this:

@Echo Off
msg * Hello World
pause

=)
JustBurn (author) in reply to dx340Oct 22, 2008. 7:32 PM
nice! although message service only work on Win2K based OS.. but still fun to do some interesting pop-up messages with batching :)
duct tape says: Jun 28, 2007. 4:00 PM
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. ;)
Bolicao says: May 18, 2007. 7:36 AM
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 569 says: May 5, 2007. 11:15 PM
I didn't understand a thing you said in this instructable.... :'(
mikesty says: Jul 17, 2006. 6:08 PM
echo Hello World! ;) Pretty neat stuff though. You know quite a bit about this :)
JustBurn (author) in reply to mikestyJul 17, 2006. 8:05 PM
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.
mikesty in reply to JustBurnJul 18, 2006. 1:14 PM
Bahaha, did gates not once say, "No one will ever need more than 640K!" or something like that?
Mz3FRS in reply to mikestySep 24, 2006. 11:00 AM
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 in reply to Mz3FRSJan 11, 2007. 1:20 PM
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) in reply to mikestyJul 19, 2006. 5:02 PM
"640K ought to be enough for anybody.", but Bill Gates deny that actually said this. :)

http://en.wikiquote.org/wiki/Bill_Gates
Mr.Devious says: Jan 3, 2007. 6:25 AM
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) in reply to Mr.DeviousJan 3, 2007. 6:39 PM
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.
Mr.Devious in reply to JustBurnJan 6, 2007. 8:17 AM
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
Delta629 says: Oct 3, 2006. 3:09 PM
Cool, I haven't seen debug used since the late '80s.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!