Hypercubed Blog

Incoherent chatter on issues related to science, computing, and philosophy.
Random chains of thought from a scattered mind.

Hypercubed Blog has Moved!

 

Debugging Langton's Ant (way too long)
Posted Tuesday, April 12, 2005 4/12/2005 09:10:00 PM

So yesterday I mentioned that A. K. Dewdney was a contributing author of many Computer Recreations articles appearing in Scientific American magazine. While in collage I used to rife through back issues of Scientific American magazines to read every Computer Recreations and Mathematical Recreations I could find. One of the most memorable articles was The Ultimate in Anty-Particles by Ian Stewart appearing in the July 1994 issue. In this article Stewart describes a simple cellular automaton invented in the 1980s called Langton's Ant. Langton's Ant is a fascinatingly simple example of cellular automata similar to Conway's Game of Life . With a very simple rule set the ant will create very complex patterns that appear random. However eventually the ant will enter a repeating pattern and you realize that it is not random at all.

A Langton's Ant code was one of the first pieces of software I ever wrote. At the time I owned a cheap Tandy computer that couldn't even run a ASM compiler much less a higher level programming language like C or PASCAL (or at least one I could afford). So what did I write it in? Well believe it or not I wrote my application in MS-DOS debug. That's right in debug. If you know anything about debug you know that that is a real feat. Let me try to explain. Well, the lowest level on computer programming is writing in machine language. That is actually writing in the 1 and 0 that computers understand. Well, I don't believe there is anyone in this world that can program directly in machine code. The next level up is assembly language. At this level you are writing in a type of shorthand code that represents the machine commands that will be sent to the CPU. The language commands consist of moving numbers in and out of memory and hardware (i.e. the screen) locations. As you write your code you need to jump around in memory quite a bit. The good thing about using an assembly language compiler is that you can assign names to various memory locations so that you don't need to know the exact memory address. In addition as you modify the code the memory addresses change.

But I didn't have a assembly language compiler.. instead I had debug. Debug is a MS-DOS tool that was intended to view and modify data in memory. So using debug you can actually view pieces of memory and print out the assembly language commands. So what I actually had to do was write out the entire code on paper before hand, type the code directly into memory using dummy values for the memory locations then go back and change all the memory locations to the actual locations. Run, debug, repeat. It was not easy. Luckily Langton's ant was easy to write. I have never again written anything in assembly language but writing that piece of code taught me a lot about computers that I never would have gotten using Visual Basic or C++. I have long ago lost the code and the executable but several years ago I wrote a version in Visual Basic that I turned into a screen saver. More fancy but defiantly, but not as interesting.

It is also interesting to note that Ian Stewart (the author of the Scientific American article that started in all for me) has also written a couple of books regarding FlatLand by by Edwin A. Abbott one of the inspirations for A. K. Dewdney's The Planiverse .

0 Comments:

Post a Comment


:


Links to this post:

Create a Link

<< Home

Previous Posts

Google
 
Web hypercubed.blogspot.com
www.hypercubed.com