Live data from Hacker News

The smallest Hello World program

blog.lohr.dev

1–10 of 53 posts

Re: The smallest Hello World program

#2
These challenges are funny - they remind me of the old days. Back in the DOS/Windows days, we used to have the .com format, which was perfect for tiny programs. One could even write a program of less than 10 bytes that could actually do something!

We've come a long way since then, and is like, at some point, nobody cared about optimizing executable size anymore

Re: The smallest Hello World program

#5
post #2

These challenges are funny - they remind me of the old days. Back in the DOS/Windows days, we used to have the .com format, which was perfect for tiny programs. One could even write a program of less than 10 bytes that could actually do something! We've come a long way since then, and is like, at some point, nobody cared about optimizing executable size anymore

JMP FFFF:0000

Re: The smallest Hello World program

#7
This is pretty bad. Let's start with the very first instruction:

  mov rax, 1
An actual "mov rax, 1" would assemble to 48 B8 01 00 00 00 00 00 00 00, a whopping TEN bytes.

nasm will optimize this to the equivalent "mov eax, 1", that's 6 bytes, but still:

  xor eax, eax ; 2 bytes
  inc eax      ; 2 bytes
would be much smaller. Second line:

  mov rdi, 1
You already have the value 1 in eax, so a "mov edi, eax" (two bytes) would suffice. Etc. etc.

Re: The smallest Hello World program

#8
My favorite language for implementing short Hello World programs in is HQ9+ [1].

Joking aside, this page [2] used to be a great tutorial on writing small ELF binaries, but I'm not sure whether it will still work in 64-bit land. It proved very helpful for writing a 4K intro back in 1999.

[1] https://esolangs.org/wiki/HQ9%2B

[2] https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...

Re: The smallest Hello World program

#10
post #7

This is pretty bad. Let's start with the very first instruction: mov rax, 1 An actual "mov rax, 1" would assemble to 48 B8 01 00 00 00 00 00 00 00, a whopping TEN bytes. nasm will optimize this to the equivalent "mov eax, 1", that's 6 bytes, but still: xor eax, eax ; 2 bytes inc eax ; 2 bytes would be much smaller. Second line: mov rdi, 1 You already have the value 1 in eax, so a "mov edi, eax" (two bytes) would suff…

  push 1
  pop rax
is even shorter (credit: https://old.reddit.com/r/programming/comments/q6mnz1/what_is...)
Post reply on HN