December 19, 2012

Remian: a modern virtual machine

Anyone who follows me on Twitter has probably read that I’m building a virtual machine of my own, named Remian. I’ve reached v0.1.1 and an initial release, so now is the perfect time to talk about why you should try it.

A powerful property of any true computer is the ability to simulate any other computer given sufficient time. This is known as Turing Completeness, and means that we can program our own computers: instead of designing a computer and wiring it up, we can build it in software as a virtual machine.

Understanding computers improves you as a programmer

As modern programmers we use high-level languages whenever possible, since programmer productivity tends to drop as we move to higher-performance languages. Yet when we try to solve difficult problems, it is all too easy to accidentally cripple code performance because you don’t understand what the computer is doing.

The best way to avoid these problems is to learn about computer architecture and the basics of Assembly programming. Most programming code is executed as something like assembly code, so understanding it better can be invaluable. This might be unlikely to turn into your day job, but it’ll help you make better decisions.

The bad, bad and ugly of x86 Assembly

Unfortunately, getting practical experience with Assembly proves not to be straightforward. Most modern computer processors are based on decades-old designs. As opposed to the instruction sets you might find in an undergraduate-level text, there’s decades-worth of rabbit-hole to follow before you can stop running into bizarre bugs.

Finding a modern Assembly reference that’s not written for experts is difficult. Whilst I’ve written up notes on the matter, I’m interested in Assembly programming as a mere curiosity. I don’t want to program all my software in it, I just want others to be able to dive into hacking Assembly as easily as they might JavaScript.

Virtual machines for Assembly

The solution used by Universities seems to be virtual machines, in the form of unpolished software..You sit in front of a GUI and type in your code. However all the experience with such software I’ve accrued suggests that the toolchains suck. At best you’ll have a working textarea to type in; at worst you’ll have constant crashes.

Remian is built from my experience of this. There’s no bloated Windows installer, no barely-functional Java UI. Just install Remian with gem install remian and watch the instructions execute remian execute your-assembly-file.rem.

For now there’s a fairly short list of instructions and just one computer design, but the machine has deliberately been designed for flexibility. The long term plan is to support a wide range of computer designs, from tape-based Turing Machines to stack-based computation.

If you’d like to find out more, browse Remian’s source on Github or take a look at a program I built earlier.