This is pretty bad. Let's start with the very first instruction:<p><pre><code> mov rax, 1
</code></pre>
An actual "mov rax, 1" would assemble to 48 B8 01 00 00 00 00 00 00 00, a whopping TEN bytes.<p>nasm will optimize this to the equivalent "mov eax, 1", that's 6 bytes, but still:<p><pre><code> xor eax, eax ; 2 bytes
inc eax ; 2 bytes
</code></pre>
would be much smaller. Second line:<p><pre><code> mov rdi, 1
</code></pre>
You already have the value 1 in eax, so a "mov edi, eax" (two bytes) would suffice. Etc. etc.
Here's a tiny DOS COM file that does it in 18 bytes:<p><pre><code> ;; 18 bytes
DB 'HELLO_WOIY<$' ; executes as machine code, returning SP to original position without overwriting return address
mov dx, si ; mov dx,0100h MS-DOS (all versions), FreeDOS 1.0, many other DOSes
xchg ax, bp ; mov ah,9 MS-DOS 4.0 and later, and FreeDOS 1.0
int 21h
ret
</code></pre>
(credits: <a href="https://stackoverflow.com/questions/72635031/assembly-hello-world-execution-file-less-than-20-bytes" rel="nofollow">https://stackoverflow.com/questions/72635031/assembly-hello-...</a>)
My favorite language for implementing short Hello World programs in is HQ9+ [1].<p>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.<p>[1] <a href="https://esolangs.org/wiki/HQ9%2B" rel="nofollow">https://esolangs.org/wiki/HQ9%2B</a><p>[2] <a href="https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html" rel="nofollow">https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...</a>
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!<p>We've come a long way since then, and is like, at some point, nobody cared about optimizing executable size anymore
here's an 80 byte x86_64 linux 'hello world' (okay, not 'Hello world!'). convert to binary with xxd -r -p:<p><pre><code> 7f454c46488d3537000000ffc7b20eeb03003e00
b001eb1a01000000050000001800000000000000
1800000005000000b03c0f05ebfa380001006865
6c6c0000010068656c6c00006f20776f726c640a
</code></pre>
i'm sure this can be improved -- but i could never get any x86_64 linux elf to under 80 bytes. see if you can fit the exclamation point still.
Linking a similar, very popular past example of this:
Teensy: <a href="https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html" rel="nofollow">https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...</a>
I realize TFA is trying for object code, but for source code, QuickBASIC (and its successors) isn't bad:<p><pre><code> ? "hello, world!"
</code></pre>
PILOT eliminates the quotes:<p><pre><code> T:hello, world!
</code></pre>
Of course a typical REPL (Python, JavaScript, Lisp, etc.) will print out something similar (but often quoted) if you just type the quoted string.<p>And I'm sure there is already some language (call it HELLO) which simply prints "hello, world!" for an empty program.
Now, can we make it even smaller applying <a href="https://nathanotterness.com/2021/10/tiny_elf_modernized.html" rel="nofollow">https://nathanotterness.com/2021/10/tiny_elf_modernized.html</a> ? We shouldn't need the full ELF header...