The smallest Hello World program
blog.lohr.dev
The smallest Hello World program
1–10 of 53 posts
Re: The smallest Hello World program
#2We'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
#3Re: The smallest Hello World program
#4Re: The smallest Hello World program
#5These 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
#6Now, can we make it even smaller applying https://nathanotterness.com/2021/10/tiny_elf_modernized.html ? We shouldn't need the full ELF header...
Re: The smallest Hello World program
#7 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
#8Joking 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
#9Because it would be much smaller in a bat file than contains :
echo Hello World!
Re: The smallest Hello World program
#10This 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...)