Artificial Life in computer. Including evolution of course...! Original idea by Tom Ray. With simple assembler language, you can make Tierra program (called gene or genome) that copy itself and start evolution by mutations.

Tom Ray has written lot of texts about artificial life, evolution and genetic algorithms. Just search the internet for more complete information of Tierra.

My implementation of Tierra is fully character based and it uses only standard C++ input (cin) and output (cout, printf) functions. So I think it's quite portable.

More detailed description of Tierra

Basic operation of Tierra program:

At start, program just copy itself repeatedly. You can check this first tierra program from source code section below.

1. Calculate needed memory block (own size, this is calculated only at first copy).
2. Allocate enough memory for child process
3. Copy own code to allocated memory
4. Ask operating system to start child
5. Goto 2.


TierraCPU is virtual multitasking CPU. It has few registers, which are accessible with Tierra Assembler opcodes.


int ax; // address register
int bx; // address register
int cx; // numerical register
int dx; // numerical register
int flag;
int sp; // stack pointer
int stack[10]; // stack
int ip; // instruction pointer

Assembler opcodes:

Assembler commands fits in one byte (actually in 5 bits)

Opcode Description
nop_0 template 0
nop_1 template 1
or1 flip low order bit of cx, cx^=1
shl shift left cx, cx<<=1
zero set cx to zero, cx=0
if_cz if cx==0 execute next intruction
sub_ab substract bx from ax,result to cx, cx=ax-bx
sub_ac substract cx from ax, ax=ax-cx
inc_a increment ax, ax++
inc_b increment bx, bx++
dec_c decrement cx, cx--
inc_c increment cx, cx++
push_ax push ax on stack
push_bx push bx on stack
push_cx push cx on stack
push_dx push dx on stack
pop_ax pop to ax
pop_bx pop to bx
pop_cx pop to cx
pop_dx pop to dx
jmp jump (nearest)
jmpb jump (backward)
call call subroutine (nearest)
ret return from subroutine
mov_cd move cx to dx, dx=cx
mov_ab move ax to bx, bx=ax
mov_iab  move instruction at [bx] to [ax], [ax]=[bx]
adr search template (nearest) address to ax
adrb search template (backward) address to ax
adrf search template (forward) address to ax
mal allocate memory, cx=size, return address in ax
divide cell division, start of cell in ax

Assembler (t_asm) and disassembler (t_dasm):

These tools use stdin for input and stdout as output. So it is nice to redirect those to file.

Usage: t_asm <input-file >output-file

t_asm compiles assembler commads (ascii file) to bytecodes (binary file). t_dasm compiles bytecodes back to  assembler listing. Assembler listing is commented with those descriptions above.

Source code & executables

Source for Tierra <tierra.tgz> (15k)
Here is sample Tierra program <80aaa.asm> (3k)
Statics file from one run of Tierra <statics.csv> (8k)

ELF executables <tierra-linux-elf.tgz> (150k)




Screenshot at Tierra startup. Program takes filenames as parameters. Those bytecode files are loaded to virtual memory in given order and system is prepared to run.

[korma@localhost ajo1]$ ../tierra ../80aaa

loading ../80aaa
cycles left: 31

-----General System screen-----
CPU current/all 1/1
cycles this/all 1/1 (0 M)
free memory 255920 bytes in 1 blocks
used memory 80 (0 %)
0 bit flips, 0 invalid instructions, 0 killed CPUs
Different genomes 0
Errors 0
free_mem=0k, cpu_queue=0k, gene_store=0k, temp_store=0k
start=0 size=80 (0,0)
-----registers----- pid/max:0/0
ax=0 bx=0 cx=0 dx=0
ip=1 sp=0 flag=0
stack: 0 0 0 0 0 0 0 0 0 0
-----Next opcodes-----
[ 0] 0: nop_1
[ 1]-> 1: nop_1
[ 2] 2: nop_1
[ 3] 3: nop_1
[ 4] 4: zero
[ 5] 5: or1
command (h=help):

"General System screen" section shows information about system, memory and processes.
"registers" section shows registers for currently running process.
"Next opcodes" shows opcodes at instruction pointer

The control keys are:

command (h=help): h
d - step 1 instruction
s # - step # instructions
w # - write to disk all genes at size #
g - print genebank
m - print memory info
e - print error info
t - toggle error counting
c - print cpu table
h - print keys
q - quit
command (h=help):

Example command:

s 300000

This command run 300 000 instructions with Tierra system. After that the General System screen is printed again.

When running, new genomes (evolved programs) are written to file in current directory. Filename is made up of genome size and counter number. Example "43_157" means that size is 43 opcodes and that was 157th written genome.


Tierra writes some statics about The Life to file (statics.csv, check source code section). This file is easy to view in StarCalc or other Spreadsheet program (MS Excel is suitable, if you don't have any better) as Comma Separated Values. This makes it easy to draw charts about life.

markku (dot) t (dot) korsumaki (at) mbnet (dot) fi
Back to home (code::web)

Last modify: