Ernst-Hugo Järegård being awesome.

I have been spending the entire weekend writing a assembler in Java for my automaton. I felt that i needed to give it a name while i worked on it so i have decided to call it the Ernst-Hugo Automaton after the Swedish actor and awesome person Ernst-Hugo Järegård. I  have used the the Automaton package that i wrote earlier with some changes. I had to change some of the scoping of the classes to make them work with the new Assembler package.

The code

The Assembler class is the a very ugly class which contains a constructor which acts as a main loop where the basic input parsing occurs. Most of the methods in the assembler class handles the parsing of the input but it also handles what is to be sent to be assembled and the running of the program. Valid assembly code is then sent from the Assembler class to the Program class when the assemble method in Program is called. The Program class is the program that you are working on. It contains both the assembly code for the program and the assembled program(given that it has been assembled). The Program class also contains the assemble method and the other methods needed for the assembling of the program. I know i should put this in a separate class… but i didn’t.

I have tried to write good looking code but i know that especially the Assembler class is mighty ugly. i  have also tried to implement some form of exception handling. There is also a somewhat extensive documentation of the classes used. I know that the documentation is rather incoherent and does not really adhere to any specific formating convention but i guess its better than nothing.

As of now the assembler does not implement that many features apart from some very basic editing of the input. It would be very nice to add things such as the ability to load and save programs. Right now the assembler cant handle any functions except for a function to add Jump lines.

The Automaton class contains some rudimentary unit testing methods. I really only wrote those for educational purposes and they can be pretty much disregarded but they are included just for fun.

The documentation can be found here.

The JAR containing the actual program and the source code can be found here. To run the program you will need to have a ANSI compatible command line interface or the program will look really stupid. It would not be that difficult to re factor it to normal output not using ANSI formatting. Just rewrite the AnsiDrawer class. It shouldn’t be that hard.


The operation of the assembler is pretty basic. The code is simply inputed using the symbols :
( 0 , 1 , . , ! , + , x , & , < , > ).  Which are the same as specified in previous posts although the symbols have been changed to ASCI equivalents.. The index (row) where the code will be added is shown before the “:” on each line. The index can be set by the commands which will be specified in detail later.

The jump command is implemented in this assembler and is typed as “#jump:pos:target”. Only one Jump will be added on a line and the rest of the line will be padded with Drop. You can add a Jump command with the target lying outside of the program. But when you assemble the program all Jump operators has to point to a line in the assembly code. Remember that all of the jump targets are absolute! so inserting lines in your program can screw up your Jumps.

The commands

All of the commands are preceded with a “§” symbol and are as follows:

Prompts the user for the memory size of the program and then creates a new Program instance. This has to be done before any code can be written. Calling new again will over ride any code or assembled program.

Runs the program given that it has been assembled. Prompts the user for a starting configuration of the memory. The program will run for a maximum of 200 steps in order to avoid infinite loops.

Prints out the assembly code.

Assembles the program. Will fail if any Jump targets lies outside of the program length. Prints the assembled code when done.

Clears the screen.

Prints a help text.

set n
Will set the index to n. The index will then increment from n when a line of code is entered. All lines after n will be pushed down. Using set will screw up your Jumps if you are not careful.

replace n
Replaces line n with the next line of code entered. The index then returns to the end of the assembly code.

Resets the index to the end of the assembly code

quits the program.


Here follows a little usage example. It is the 1 bit adder that i showed in the first post about this automaton. This example should give you a little better understanding of how the assembler works.

 Enter the memory size of the program:
 You may now begin coding!
 0: .....
 1: .<.>.
 2: <>..x
 3: ...<.
 4: .<>..
 5: .&<>.
 6: ...&x
 7: ..>..
 8: ...+.
 The command is silly! Use a propper one!
 Compiling: default
 It would appear as if the program has compiled without any major trouble!
 Please enter the starting configuration
 0 00101
 1 00101
 2 01111
 3 10110
 4 10100
 5 11000
 6 11000
 7 11000
 8 11100
 G 11110

Further development

I have been thinking a bit about writing some form of language for the system capable of some more complicated operations. I have figured out a way of creating a addressable memory space with the Ernst-Hugo automaton which would enable more advanced programming using a fixed but arbitrary word length. Although creating a new language would require a lot of  effort to implement but it would be really fun to be able to write more complicated programs for it. But that depends on the interest from you folks. If you really want me to write one i would definitely do it or if anyone of you would like to do that you are more than welcome! Just email me if you have any questions about the code or want to start a collaborative project with the Ernst-Hugo Automaton!


I have been spending the weekend rewriting the automaton in Java and watching Beavis and Butthead. I must say that MTV was fucking awesome back in the day. Seriously Nitzer Ebb, The Cult, WALL OF VOODO! and tons of other great bands and nowadays the only thing they show is fucking snookie. Well back to the geeking.

The JUMP operator

Apart from the rewrite i have made some minor changes. I have changed the names of the “take left” and “take right” operators to “Clone Left” & “Clone Right” which makes much more sense as cloning whats on the left is actually what the operators do. I have also implemented the Jump operator. The Jump operator is very special since it requires a Target to be defined for each Jump . Each row of the maze can only contain one Jump operator and any operators to the right of the Jump operator will not be evaluated in my Java implementation. The Jump operator will only issue a jump to its specific target if the symbol directly above it is a 1 otherwise the jump operator will be equivalent with the Drop operator. Its wise to only put one Jump operator on each row of the maze and no other operators.

The Java implementation is pretty straight forward. You can find the code here and just compile the Automaton.Java file. Oh and you might want to have a ANSI capable terminal.

The next update will be about the system for creating a addressable memory arbitrary word size i figured out and hopefully some form of assembler for the system. I have to read up on regular expressions in Java.

A few days ago i had an idea for a simple automaton that could be used as a model of computation whose operation would be somewhat intuitive, powerful (Although not right now) and yet different from conventional models of computation to make it interesting. I am of course completely aware that this model probably is nothing more than a restatement of some other automaton. Although i would like to point out that i figured all of this out on my own though without any major interference from the real world. All of the coding has been done from scratch in Mathematica.

I will in this post give a very informal description of how the automaton works and i hope that i in a later post will be able to give you a more formal definition and a in-depth analysis of the workings of the system.

General operation

The mazer processes data in a rather simple way. The data  is stored in the ledge and is then fed down trough the maze in steps(t) until it hits the ground. One can view the automaton as data “falling” trough a maze.

The components

The Ledge

The so-called ledge is a rank one cyclic array of size l containing the symbols 0 or 1. The size of the ledge determines the “memory” which the machine has available.

The Ground

The ground is identical in its construction to the ledge. The ground is the final step that the machine can reach. Right now (with no jump operator) the data will definitely reach the ground eventually.

The Maze

The maze is as you might have guessed by now the actual interesting part of the system. The maze is a rank two array containing symbols from the operators alphabet. Each successive level of the maze gives a set of ordered operators which given a ledge above them determines the configuration of the ledge at the next step.

The Operators

The operators are symbols in the maze which determines the next symbol at the same position(column) as the operator. Well i can understand if you didn’t really get that. Well let me put it to you like this:
ThingHere we have introduced the array S which is an intermediate ledge. What we have here is that at step t the new symbol in the intermediate ledge(S) at position i  will be given by the operator located in the maze(M) at step t and position i. Said operator only takes the three symbols in L located at positions i – 1, , i + 1.

The Operator Alphabet

Given what we know above we can no start to look at the specific operators. We will use a somewhat different notation where:VariablesThis makes the description of the operators more intuitive. Below follows a list of the different operators: Untitled-1These are all the operators we will use except for  the jump operator but i will implement that later.

Example: 3-Bit Ripple-Carry Adder

Well here i will show you the code for a very simple three bit ripple-carry adder which will take two 3 bit numbers, add them and produce a 4 bit output. To do this we will connect three full-adders so obviously the first step will be to construct a simple full-adder. A full adder takes the bits A,B,C and outputs two bits S and Co where S is the sum A+B+C and Co is the carry out bit. The formula for S and Co is:

To do this we will configure the Maze as follows, With the specific positions for the input and output marked:


And then we just take three of these and connect them together using a chain of Take Left and Take Right and we get a 3-Bit adder:

Full AdderAnd isn’t that just pretty awesome!
Now lets see if it works! I will just Configure the ledge to correspond to 7+5 which would in binary be 111(A)+101(B). We know that 7+5=12 so we would be expecting to see That the last four bits on the ground are 1100. So then let’s try it! Below i will show all of the steps in the operation:
Adding5and7And it works! How incredibly neat!!

Whats next?

Well that’s it for this brief introduction. I will soon follow-up this post with a more detailed description on its operation and the “assembler” which i have written for the system. Later  we will also implement the special jump operator(although i might have to do a complete rewrite of the code to get that working).

And one day there will be a more popper analysis the system.

I’m fully aware that i probably explained this in the most confusing and incoherent way so please don’t be afraid to ask any questions or leave feedback!

Keep it Real!
//The Grandmother