News for hackers. Stuff that matters.
Re:Write your own Virtual CPU in C++ by fordacious on Saturday September 27, 2014 @10:09PM (#8378738)
I 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 - C

http://pastebin.com/L79CeeGB - Haskell

http://pastebin.com/LybWwGzm - JS

http://pastebin.com/ZVDiRmP6 - MHS this language cant take input (its an educational toy language for a course)

Re:Write your own Virtual CPU in C++ by Shengbo on Sunday September 28, 2014 @10:13AM (#8379764)
As 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.
Re:Write your own Virtual CPU in C++ by userbinator on Saturday September 27, 2014 @10:07PM (#8378732)
I 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/

Re:Write your own Virtual CPU in C++ by andrewchambers on Saturday September 27, 2014 @05:30PM (#8378262)
My mips cpu which boots linux -

https://github.com/andrewchambers/cmips

Re:Write your own Virtual CPU in C++ by ggambetta on Saturday September 27, 2014 @04:47PM (#8378164)
I'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

[2] http://gabrielgambetta.com/remakes.html

Re:Write your own Virtual CPU in C++ by suprjami on Saturday September 27, 2014 @06:42PM (#8378412)
You'll probably be interested in this: 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.

Re:Write your own Virtual CPU in C++ by dkarapetyan on Saturday September 27, 2014 @09:33PM (#8378691)
A 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-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.

Re:Write your own Virtual CPU in C++ by jarcane on Saturday September 27, 2014 @04:03PM (#8378025)
I'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 if you're curious.

Re:Write your own Virtual CPU in C++ by adamnemecek on Sunday September 28, 2014 @12:51AM (#8378967)
If 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-Princip....
Re:Write your own Virtual CPU in C++ by Zardoz84 on Sunday September 28, 2014 @04:09AM (#8379222)
Re:Write your own Virtual CPU in C++ by hello_hn on Sunday September 28, 2014 @12:12AM (#8378908)
Another one in JS that boots linux:

http://riscv.org/angel

Re:Write your own Virtual CPU in C++ by acqq on Sunday September 28, 2014 @01:51AM (#8379058)
It's orders of magnitude slower than Bellard's JSLinux (http://bellard.org/jslinux/) on my iPad. I haven't waited until the end.
Re:Write your own Virtual CPU in C++ by hello_hn on Sunday September 28, 2014 @02:43PM (#8380560)
That's largely (entirely?) because it's a 64-bit system whereas jslinux is 32-bit (JS does not natively support 64-bit ints).