4 ms·
Write your own Virtual CPU in C++
- jarcane 12y agoI've done this in Racket. It was quite a fun little learning project. I've been meaning to dust off the core and add some more I/O hardware to it though. https://github.com/jarcane/MicroMini https://github.com/jarcane/MicroMini if you're curious.
- ggambetta 12y agoI've written an (incomplete) 8086 emulator in C++ [1] as part of a bigger project [2]. This kind of thing is really fun to do and gives you a lot of insight of how CPUs work (as a black box, though). [1] https://github.com/ggambetta/emulator-backed-remakes https://github.com/ggambetta/emulator-backed-remakes [2] http://gabrielgambetta.com/remakes.html http://gabrielgambetta.com/remakes.html
- suprjami 12y agoYou'll probably be interested in this: http://reassembler.blogspot.com/ http://reassembler.blogspot.com/ This guy spent three years disassembling the Outrun arcade ROM, then 2 years re-implementing it in C++, then extending his engine with features like high fps and new game modes, and is now onto creating extender tools like track and time editors. Along the way he found several new bugs and provides a fixed ROM which can be flashed to the arcade board. He's also got a project to develop an SoC which uses his engine to run an arcade cabinet, completely replacing the original board. It's a phenomenal effort and an amazing blog to read back through.
- andrewchambers 12y agoMy mips cpu which boots linux - https://github.com/andrewchambers/cmips https://github.com/andrewchambers/cmips
- dkarapetyan 12y agoA nice book I have found on the topic of virtual machines as they relate to programming languages is http://www.amazon.com/Compiler-Design-Machines-Reinhard-Wilhelm/dp/3642149081 http://www.amazon.com/Compiler-Design-Machines-Reinhard-Wilh.... It is a pretty good book although the focus is less on emulating actual hardware and more on designing and implementing custom virtual machines as compilation targets for imperative, functional, and logic languages. I kinda wish there were more meetups that focused on this kind of stuff instead of the latest and greatest frameworks. This kind of fundamental theory is applicable in any kind of application and framework setting.
- userbinator 12y agoI wish there were more people who thought about and understood these low-level basics; it feels like today, almost everyone who uses a computer is at such a far level of abstraction from the base hardware that they've lost the intuition for how computers behave the way they do and everything seems mysterious to them. This book is highly recommended to anyone interested in how computers work; it starts off with very basic electronics and goes up to a full CPU, plus some software stuff near the end: http://www.charlespetzold.com/code/ http://www.charlespetzold.com/code/
- fordacious 12y agoI got this idea from a friend, but whenever I wanted to learn a new language, I would quickly hack out a 4001 emulator in that language. Its an interesting but quick challenge. http://pastebin.com/YkhRsuih http://pastebin.com/YkhRsuih - C http://pastebin.com/L79CeeGB http://pastebin.com/L79CeeGB - Haskell http://pastebin.com/LybWwGzm http://pastebin.com/LybWwGzm - JS http://pastebin.com/ZVDiRmP6 http://pastebin.com/ZVDiRmP6 - MHS this language cant take input (its an educational toy language for a course)
- Shengbo 12y agoAs a beginner studying C, Java, Python and JS at the same time this is very interesting and educational. Thank you very much for posting these links.
- hello_hn 12y agoAnother one in JS that boots linux: http://riscv.org/angel http://riscv.org/angel
- acqq 12y agoIt's orders of magnitude slower than Bellard's JSLinux (http://bellard.org/jslinux/ http://bellard.org/jslinux/) on my iPad. I haven't waited until the end.
- hello_hn 12y agoThat's largely (entirely?) because it's a 64-bit system whereas jslinux is 32-bit (JS does not natively support 64-bit ints).
- adamnemecek 12y agoIf this is something that tickle's your fancy, you should check out 'The Elements of Computing Systems' http://www.amazon.com/The-Elements-Computing-Systems-Principles/dp/0262640686 http://www.amazon.com/The-Elements-Computing-Systems-Princip....
- Zardoz84 12y agoIn C++ , a full virtual computer : https://github.com/trillek-team/trillek-vcomputer-module https://github.com/trillek-team/trillek-vcomputer-module