TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An 8086 PC emulator in 4043 bytes

196 pointsby epsylonover 11 years ago

15 comments

mmastracover 11 years ago
This is interesting, though it might be a bit of a cheat. He&#x27;s put some data in the BIOS image to assist in decoding instructions (not to take away from how amazing this is!):<p>&quot;CPU supports the full 8086&#x2F;186 instruction set. Due to the complexities of the 8086’s arbitrary-length instruction decoding and flags, 8086 instructions are first converted to a simpler intermediate format before being executed. This conversion, along with instruction lengths and how each instruction modifies the flags, is assisted by some lookup tables which form part of the BIOS binary.&quot;<p>With that in mind, the BIOS is _hand-written_ and about 12kB (gzips to &lt;4kB), so that&#x27;s also a fantastic achievement. All-in-all, this is a wonderful entry.
评论 #7012802 未加载
ori_bover 11 years ago
I went through and reformatted the code, after expanding all of the macros that contained unbalanced parens: <a href="http://eigenstate.org/cable3-formatted.c" rel="nofollow">http:&#x2F;&#x2F;eigenstate.org&#x2F;cable3-formatted.c</a><p>I still haven&#x27;t puzzled out exactly what all the variables are, but I think that this makes the structure much clearer.
petercooperover 11 years ago
The source itself: <a href="http://ioccc.org/2013/cable3/cable3.c" rel="nofollow">http:&#x2F;&#x2F;ioccc.org&#x2F;2013&#x2F;cable3&#x2F;cable3.c</a><p>Or after running through preprocessing (not a huge help I found, sadly): <a href="https://gist.github.com/peterc/8259713" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;peterc&#x2F;8259713</a>
评论 #7012949 未加载
评论 #7012558 未加载
userbinatorover 11 years ago
&gt; Instruction codings are complex and irregular in size and structure, with multiple addressing modes and no consistent memory placement for operands, very often multiple possible encodings for the same instruction<p>It&#x27;s only complex and irregular if you look at it wrong. ;)<p>The x86 (like the 808{5,6} and the Z80) instructions look organised in an octal format: ftp:&#x2F;&#x2F;mipt.cc&#x2F;Opcode.txt<p>I haven&#x27;t inspected the code in any detail to see if it takes advantage of this.
bitwizeover 11 years ago
I thought &quot;Wow, that&#x27;s a neat trick.&quot;<p>Then I saw AutoCAD, Flight Simulator, and Windows.<p>Mind = blown.
kyberiasover 11 years ago
Here&#x27;s a link to a fully functional Windows binary (built with Visual Studio 2013):<p><a href="http://sdrv.ms/1hodqjP" rel="nofollow">http:&#x2F;&#x2F;sdrv.ms&#x2F;1hodqjP</a><p>Just add the bios and image files elsewhere.
评论 #7013048 未加载
lifeisstillgoodover 11 years ago
&#x2F;snip This entry weighs in at a magical 4043 bytes (8086 nibbles, 28,301 bits). It manages to implement most of the hardware in a 1980’s era IBM-PC using a few hundred fewer bits than the total number of transistors used to implement the original 8086 CPU. &#x2F;snip<p>Just a small reminder how far we have come - and what Moore&#x27;s law (RIP) has done for us. Yes the original PC had few enough transistors one could actually count them. NowadAys ...<p>An awesome piece of work
joeboover 11 years ago
Neat, the linked hd.img file contains windows, Simcity, AutoCAD, etc. Has anyone compiled this for Windows? If so, would you kindly post the binary? It&#x27;d be fun to play with this old software again.
coinover 11 years ago
The BIOS is part of the PC, yet it&#x27;s not included in the 4043 bytes.
评论 #7013172 未加载
TazeTSchnitzelover 11 years ago
If you&#x27;re on Linux and don&#x27;t want to bother installing a VGA font, there&#x27;s no need. Do Ctrl+Alt+F6 (or lower) to switch to a terminal and run it there, then do Ctrl+Alt+F7 to switch back later.<p>Also, if someone can tell me how to make Windows not make the emulator segfault on my machine, that&#x27;d be great.<p>EDIT: Oh, it works fine in a graphical terminal. I&#x27;m guessing SDL failing to init on a text terminal broke everything.<p>EDIT 2: ALL THIS, PLUS REVERSI! You can even play Reversi!
kyberiasover 11 years ago
MS Visual C++ 2013 chokes on this with &quot;&#x27;KB&#x27; undeclared identifier&quot; error.
评论 #7012940 未加载
mschuster91over 11 years ago
Has someone already unobfuscated the source code?
评论 #7035588 未加载
lelfover 11 years ago
All IOCCC winners — <a href="http://ioccc.org/years.html#2013" rel="nofollow">http:&#x2F;&#x2F;ioccc.org&#x2F;years.html#2013</a>
faragonover 11 years ago
Is licensed&#x2F;copyrighted? Do the IOCCC have any implicit license?
kriroover 11 years ago
Fantastic. Finally some &quot;hacker news&quot; on Hacker News ;P