Apollo 11 Moon Landing Code

Neil Armstrong was the first man to set foot on the Moon 50 years ago. Apollo 11 was the craft that took them there. Your iPhone is 120 Million times more powerful than the computer that took men to the moon. It was an extraordinary feet of engineering and science that got us there. The brains of the Apollo mission were controlled by the AGC (Apollo Guidance Computer).

The software engineering team was lead by Margaret Hamilton and their work survives on GitHub thanks to a NASA ex-intern named Chris Garry. A few years back he collated and uploaded all of the AGC’s source code to GitHub. It’s all available for you to download and explore.

The code is written in a special version of Assembly, specifically designed to control Apollo’s hardware. I will not pretend I understand it all but I will list some interesting and fun facts about this code. Even in such a serious and complex mission, the software engineers found a way to introduce some fun facts and jokes in their code!

Before I talk about the code let me explain the different parts of the mission. The Apollo 11 spacecraft was sent to Earth orbit on top of the Saturn V rocket. The spacecraft then detached to continue its journey to the moon. Here’s a diagram showing its various components (source: Wikipedia).

The two main parts that had a Guidance Computer are the Command Module and the Landing Module (aka LEM). The Command Module was the main vehicle that took the astronauts from the Earth to the Moon’s orbit and back to Earth. The LEM was used for landing on the surface and getting back to the Command Module.

The source code is split into two parts. One for the Command Module’s Guidance Computer (Comanche055) and one for the LEM’s one (Luminary099).

So let’s start by looking at a file called BURN_BABY_BURN—MASTER_IGNITION_ROUTINE.AGC. The source code in this file was responsible for the LEM’s main ignition routine. So a rather important routine, but despite that the engineers still named it in this funny way.

As you can see, the code is pure assembly code. Some interesting commands that we can see here are CA, INHINT and TS.

  • CA – this is a Clear and Add command. It is more than likely a scratchpad area, where temporary code or data can be stored. But as the command suggests that data is regularly cleared.
  • INHINT – this command would turn on certain interrupts on the circuit board that would prevent any interference from other code.
  • TS – this is a Transfer to Storage command. It would simply allow for transferring of data to more permanent memory storage.

You can clearly see some of the labels used, for the program to allow program control to be passed on from one section to another. An interesting one is the STOPCLOCK. As you can see the subroutine ends with a TCF P00H. This is a Transfer Control to Fixed memory location, in this instance P00H. This is basically Program 00H, which reads as Pooh (Winnie the Pooh). That’s rather a cute little fun name used rather a lot in the code.

There are little fun names and comments everywhere you look.

Even checking if the astronauts are lying about following the appropriate commands.

This mission was humanity’s most defining moment and I am still in awe of how complex and intriguing this program was. It made sure that the three astronauts landed on the moon and returned to Earth safely. I can’t even imagine how they designed, reviewed and even tested this code with only the limited hardware resources of the time.

if you want to explore this further and play with a virtual AGC simulator then you can visit the Virtual AGC page.

Advertisement