Hello World in 28 bytes

Started by
17 comments, last by Rob Loach 19 years, 5 months ago
I'm taking an Assembly language (x86) class this semester, and the professor said he wrote a Hello World program in 28 bytes. I'm wondering exactly how he got the exe so small. My programs are never smaller than 5kb!
Advertisement
have you tried it writing in DOS assembler and as a .com ? this should do the trick... there are many tutorials on Hello World in 386 asm on the internet. try google.

regards,
m.
Keep in mind once you compile and link your asm's the program gets byte-padded so it's appropriate to the OS. When he said he did it in so few bytes, I'm willing to bet that he meant his source code was only that big. Remember, before the byte-padding comes, each instruction maps to a machine instruction.*

* - don't burn me about different instruction sets. =) I know that some RISC psuedo ops and CISC instructions span out to two or more instructions when they get translated.
It's really not that hard. COM programs don't require any header or padding.
Here's my version (21 bytes). Just paste this into a DOS prompt.
debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq
Depends on how we're defining a 'program'. And did your professor say the program was actually in assembler? For instance, this batch file is even shorter than the (correct) 21-byte program above:

<<<
@ECHO Hello, world!
>>>

The above is only 19 bytes. You can even tell your professor you've "optimized" his version. [grin]
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}
Thanks guys.
In m4:
Hello, world.

Only 14 or 15 bytes (depending upon how long a line break is).
CoV
Quote:Original post by doynax
It's really not that hard. COM programs don't require any header or padding.
Here's my version (21 bytes). Just paste this into a DOS prompt.
debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq


I don't know ASM, but that was FUN! I wasn't aware that you just type it into the prompt!
- A momentary maniac with casual delusions.
Would the instruction size of the computer make this easier? Ie, could you do it on an 8-bit machine?

edit: never mind, the example above does it in 21 bytes.
Quote:Original post by Rhaal
Quote:Original post by doynax
It's really not that hard. COM programs don't require any header or padding.
Here's my version (21 bytes). Just paste this into a DOS prompt.
debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq


I don't know ASM, but that was FUN! I wasn't aware that you just type it into the prompt!


Agreed (Although I know asm a bit) that was new to me!

Cool stuff!!!

/MindWipe
"To some its a six-pack, to me it's a support group."

This topic is closed to new replies.

Advertisement