Roger Arrick .com

1-Dimensional Cellular Automaton
in 8080 Assembly Language

18 May 2023

1-Dimensional Cellular Automaton in 8080 ASM Roger Arrick Click images for larger view

Here's a 1-dimensional cellular automaton program I wrote in assembly language that will run on an 8080 CPU and a dumb terminal showing some amazing yet natural patterns.


Cellular Automaton

Cellular automaton (CA) is a way of computationally and graphically modeling an array of cells using a rule set that governs their interaction. Depending on the rules and starting conditions some amazing patterns may emerge. The array can be any number of dimensions. The model can cause cells to change a number of different properties such as position, color, orientation. CA seems capable of modeling natural interactions we see in the real world between biological organisms, chemical processes, physical processes and more.

CA1D

The program I wrote here is a 1-dimensional CA which produces successive lines of cells on a dumb computer monitor - 'dumb' meaning only scrolling of lines in one direction are used, no arbitrary XY positioning of cells. Each cell is an asterisk and may either exist or not depending upon the rules applied to the previous row.

CA1DCPM is written in 8080 assembly language and should work as-is on a CP/M machine with its console I/O calls. Assembly can be done with CP/M's stock ASM.

CA1DISIS is a version for Intel's ISIS-II operating system which uses different console I/O calls than CP/M. There are no file operations and it should be easy to modify this for whatever console hardware you have. Since the resulting machine code uses the 8080 instruction set, it will also run on a Z80 CPU.

;Main Loop ----------------------------------------------------- ; main1: ;Display Row 1. call rout ;Calculate Row 2 from rule. call rulee ;Move Row 2 into Row 1. call rmov ;If user enters a space then pause, any other key then quit, else loop. call const ;Has user pressed a key? cpi 0 jz main1 ;No - loop. call conin ;Yes - Get character. cpi SPACE ;Space bar pauses. jnz main ;Any other char stops. call conin ;Wait for another char to resume. jmp main1 ;Loop forever.

How It Works

CA1D displays a line at a time of cells with each successive line based on the rule applied to the previous line. Lines for most terminals are 80 characters wide but this can be changed in the code. When starting, CA1D asks the operator for 2 hexadecimal characters - this is the 1-byte rule which leads to the pattern.

CA1D begins with a single cell turned ON in the center of the line. Then the rule is applied to that line and a new line is produced. This process continues forever and the pattern builds or, in many cases, diverges into a boring lifeless pattern.

Here's how the rule works:
The code cycles through each character location of the previously calculated row. It looks to see if the cell is ON or OFF, and it looks to the left and right side of it to see if they are ON or OFF. The status of these 3 locations creates a 3-bit pattern which has 8 possible combinations. This pattern is used to select one of the 8 bits in the rule and used to decide whether the current cell should be turned ON or OFF. That's done for each character in the line.

Pressing SPACE BAR pauses the display so you can study the pattern.

Cool Rules

Some of the cool rules are 12, 16, 89, 99, C3. Many rules just spit out a single column of cells while others create repeatable patterns, but some are evolving over time into amazing patterns. Stephen Wolfram wrote a whole book dealing with this type of emergence in nature. To get Wolfram's famous 'rule 30', use 1E.

Download

Here is the source code and the complied files for CA1D. Moving these files from your PC to a CP/M or ISIS-II machine can be quite tricky and far beyond the scope of this text. What I do is copy the file to a USB thumb drive and move that to my PC running imagedisk which has an operational 8" floppy drive. I use 22disk to write the file to a CP/M disk, then move that disk to my CP/M machine. Another option for transferring the files from your PC is using a communications program over a serial communication link.

CA1DCPM

For the CP/M operating system
CA1DCPM.ASM the source code in 8080 assembly for CP/M.
CA1DCPM.COM the assembled code that will run on CP/M.

CA1DISIS

For the Intel ISIS-II operating system
CA1DISIS.ASM the source code in 8080 assembly for ISIS-II.

Picture Gallery

Return

Copyright © Roger Arrick           RogerArrick.com