TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The smallest Hello World program

76 点作者 michidk5 个月前

12 条评论

bd014 个月前
This is pretty bad. Let&#x27;s start with the very first instruction:<p><pre><code> mov rax, 1 </code></pre> An actual &quot;mov rax, 1&quot; 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 &quot;mov eax, 1&quot;, that&#x27;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 &quot;mov edi, eax&quot; (two bytes) would suffice. Etc. etc.
评论 #42578644 未加载
评论 #42579025 未加载
评论 #42584274 未加载
评论 #42581354 未加载
Tepix4 个月前
Here&#x27;s a tiny DOS COM file that does it in 18 bytes:<p><pre><code> ;; 18 bytes DB &#x27;HELLO_WOIY&lt;$&#x27; ; 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:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;72635031&#x2F;assembly-hello-world-execution-file-less-than-20-bytes" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;72635031&#x2F;assembly-hello-...</a>)
评论 #42579345 未加载
评论 #42582147 未加载
smokel4 个月前
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&#x27;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:&#x2F;&#x2F;esolangs.org&#x2F;wiki&#x2F;HQ9%2B" rel="nofollow">https:&#x2F;&#x2F;esolangs.org&#x2F;wiki&#x2F;HQ9%2B</a><p>[2] <a href="https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;teensy.html" rel="nofollow">https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;teensy.ht...</a>
mrfinn4 个月前
These challenges are funny - they remind me of the old days. Back in the DOS&#x2F;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&#x27;ve come a long way since then, and is like, at some point, nobody cared about optimizing executable size anymore
评论 #42578670 未加载
评论 #42579116 未加载
评论 #42579063 未加载
评论 #42579310 未加载
评论 #42578510 未加载
5-4 个月前
here&#x27;s an 80 byte x86_64 linux &#x27;hello world&#x27; (okay, not &#x27;Hello world!&#x27;). convert to binary with xxd -r -p:<p><pre><code> 7f454c46488d3537000000ffc7b20eeb03003e00 b001eb1a01000000050000001800000000000000 1800000005000000b03c0f05ebfa380001006865 6c6c0000010068656c6c00006f20776f726c640a </code></pre> i&#x27;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.
评论 #42584394 未加载
whynotmaybe4 个月前
Could a script be a program?<p>Because it would be much smaller in a bat file than contains :<p>echo Hello World!
评论 #42579074 未加载
评论 #42579045 未加载
评论 #42583723 未加载
gr33kdude4 个月前
Linking a similar, very popular past example of this: Teensy: <a href="https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;teensy.html" rel="nofollow">https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;teensy.ht...</a>
评论 #42583174 未加载
musicale4 个月前
I realize TFA is trying for object code, but for source code, QuickBASIC (and its successors) isn&#x27;t bad:<p><pre><code> ? &quot;hello, world!&quot; </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&#x27;m sure there is already some language (call it HELLO) which simply prints &quot;hello, world!&quot; for an empty program.
评论 #42581993 未加载
fjfaase4 个月前
Would it be fair to name the program &#x27;Hello World!&#x27; and than use argv[0], which is on the stack, to print out &#x27;Hello World!&#x27;?
评论 #42584362 未加载
xpasky4 个月前
Now, can we make it even smaller applying <a href="https:&#x2F;&#x2F;nathanotterness.com&#x2F;2021&#x2F;10&#x2F;tiny_elf_modernized.html" rel="nofollow">https:&#x2F;&#x2F;nathanotterness.com&#x2F;2021&#x2F;10&#x2F;tiny_elf_modernized.html</a> ? We shouldn&#x27;t need the full ELF header...
评论 #42578530 未加载
oneshtein4 个月前
The smallest &quot;hello, world&quot; programs in Rust I did for Arduino are 294 bytes for blink and 388 bytes for hw.
Multicomp4 个月前
129 byes...supposedly that&#x27;s 2 punch cards according to Dr gpt. Small program!