Smallest “Hello, World!n” program



Even one of the simplest programs (a “Hello, World!n” program) is still much larger than it strictly needs to be. In this video, I demonstrate how to reduce executable file size starting in C, then dropping down to assembly, then even raw machine code, and more.

00:00 Introduction
01:00 Definitions and constraints
02:14 C
06:20 Assembly
13:05 ELF binary
22:36 Looser constraints
33:41 Outro

source

40 Comments

  1. <html>
    <body>Hello, world!</body>

    # my thought process was that html code for putting text on the screen is just putting the text in the code,
    # (i hope that these comments register as comments,)
    # but i mean there's all that junk like all the stuff in <here!> oh that's funny it auto printed that -> </here!>
    </html>
    oh nevermind the output was:
    Hello, world! # my thought process was that html code for putting text on the screen is just putting the text in the code, # (i hope that these comments register as comments,) # but i mean there's all that junk like all the stuff in oh that's funny it auto printed that ->

  2. If you allow any operating system and achitexture to be used, i found this program online that works on dos that is in assembally, and is 24 bytes:
    MOV AH,9
    MOV DX,108
    INT 21
    RET
    DB 'Hello, world!',0D,0A,'$'

  3. Meh, I wrote an entire functioning 4 axis 4 button gamepad/joystick driver in raw assembly, and when compiled to machine code, only took up 65 bytes of space. Not KB, certainly not MB, just 65 bytes of raw x86 machine code.

    And no, I refuse to update my terminology to that stupid KiBiByte or whatever people call that crap these days. If the base measurement is in bytes, then it's by definition in base 2, so as was in the 80s, 90s, and 2000s, a Kilobyte is 1024 bytes, a Megabyte is 1048576 bytes, and if you actually do know programming (which clearly you do OP), you ought to stick to OG terminology and leave the dummies to count in base 10.

    Sigh, rant over, but yeah it irritates the hell out of me when established computer terminology for over 40~50+ years gets arbitrarily changed (and even sounds stupid like dog kibble) because non tech savvy people have no comprehension of binary/base 2…

  4. I was totally expecting assembly. But I also expected some embedded too. Or similar. Like, even for x86, have the "OS" as the Hello World. I guess you need some initializations, so maybe still have it as a program in a very bare-bones OS. On that note, I wonder if x86 in 16 bit mode can allow for a smaller binary. For this program in particular, I guess not, since there aren't any pointers. Still, a FreeDOS executable, I expect to be able to have less bytes.

    Your work is not over Mr. Joshua! We're counting on it 😄

    Jokes aside, this was neat. I appreciate the comment annotations for the various headers, it made things much easier to understand. Though I did space out a bit starting from that 58 byte version, things got a complicated fast and I would've needed to pause and parse and was lazy to do so. Still enjoyed the full video, keep it up!

  5. @Joshua Rayton

    Why make so many constraints? If I were to write the shortest Hello World! program I'd start with the first thing I think of which is this:

    LDX #11
    Loop:
    LDA message,x
    STA $0400,x
    DEX
    BPL Loop
    RTS
    message .byte "Hello World!"

    That's 24 bytes.

  6. peak optimization
    this video needs more views really, in-depth explanation of all the methods used to compress sizes, the elf file format, etc, well done!

  7. This should have more views not speaking of subs,
    No matter how much you'll try there will still be some Terry Davis who'll make a hello world in 0.7 times smaller as your version.
    (that's not the reason to give up)

  8. Woah! Sometimes ago I was just dreaming of getting this far low level. Now with a little knowledge I have, I can assure that all of this doesn't help me to write real programs. I wrote a calculator in netwide assembly but I still don't know the advanced C++ and graphical things at all!

  9. Eliminated software bloat in exchange for kernel bloat! Next step would be designing an x86 CPU that has a ROM dedicated to the "Hello, World!n" bytes and circuitry to write it to whichever memory address gets mapped to stdout. Perhaps have a firmware running a scan on memory to inject the Hello World when a certain magic number is read from I/O. The possibilities are endless.

  10. even smaller hello world would be to use cryptinstructions or an rng, and then just run it until it eventually writes "Hello, World!"
    there are 256^13 possible combinations of ascii characters in hello world, so youd have to wait a while

  11. The kernel module is still kinda cheating, it's equivalent to having a compressor that can compress the entire of wikipedia in 0 bytes (all of it is in the decompressor). But still love the idea :3

Leave a Reply

Your email address will not be published. Required fields are marked *

You might like

© 2026 Cantinho do Vídeo - WordPress Video Theme by WPEnjoy