Skip to main content

Building a Basic Assembly Machine

Over a weekend last month, I built a basic assembly machine. It includes the following architecture:

As of right now, I haven't implemented virtual hardware to implement the architecture, instead opting for a glorified match statement.

The structure of an instruction is as follows: aabbbccc

The four operations are:

Because of the resource constrained nature of the machine, I've not set any read only registers that hold values such as for true, false, zero, or one, which means that if these values are needed, they must be set in memory and then loaded into the register.

I like this exercise because the memory in this case being used to represent all the values and the program instructions makes the relationship between the stack and heap very apparent; with only so many instructions and memory, and no 'set' values (although one could suppose that, since all registers are started at 0, that that could be used), there has to be a balance in the memory loaded of both instructions and data, and some ability to play between them.

I wrote this mostly to play with a small instruction set computer that might be fun to write toy programs in. So far, I've been able to create a program that counts to six.