Digital Descent: The Code Behind Apollo 11's Lunar Landing
Analyzing the P63 Lunar Landing Braking Phase and Celebrating Margaret Hamilton's Contributions
Chapter 1: Introduction to the Apollo Guidance Computer (AGC)
Ever since I was a young kid, the moon had always seemed like a dream. The story of Apollo 11's journey to that distant world was the stuff of legends, a story that fascinated me. And at the heart of this epic voyage was a humble, yet extraordinarily capable companion - the Apollo Guidance Computer (AGC).
The AGC was nothing short of a technological marvel birthed by the brilliant minds at the MIT Instrumentation Laboratory. It was compact, designed to withstand the brutal conditions of space, and packed to guide the spacecraft through the cosmos. With just 2.048 MHz of processing power and a 2048-word RAM, the AGC was not the powerhouse we'd imagine it to be, but it was sturdy and dependable, a true companion to the astronauts aboard Apollo 11.

Creating a computer that could navigate to the Moon and back was not easy task. The software had to be bug-free, with no room for error, as even a minor glitch could spell doom. And the hardware? It had to endure the relentless battering of space conditions, from intense radiation to the whims of microgravity.
The AGC's software was coded in a unique AGC assembly language, hard-wired into core rope memory, a form of read-only memory hand-woven with an artisan's precision.

As I dive into the saga of Apollo 11, I'll explore the P63 Lunar Landing Braking Phase, a core segment of code that orchestrated the Lunar Module's descent onto the moon's barren plains. The P63 code it's a good example of great software engineering and a foresight that was way ahead of its time, ensuring the mission's success against all odds.
In the chapters that follow, I'll try to explain the P63 Lunar Landing Braking Phase code, and paying homage to the incredible minds behind it, including my hero: Margaret Hamilton, a luminary whose contributions echo through the annals of software engineering (fun fact, she invented the name “software engineer”)
Chapter 2: Analysis of the Code for the P63 Lunar Landing Braking Phase
The Apollo Guidance Computer (AGC) is the Assembly language used for scripting the Apollo 11 mission, I've invested a bit of time to get an high level comprehension of it with the help of AGC Developer Info and GPT4 LLM. Unlike the high-level languages we often encounter today, AGC Assembly is a low-level language tailored for the specific hardware it controls.
In AGC Assembly, each instruction directly manipulate the hardware to perform desired actions. Here's how an "Hello, World Moon!" script might look, although AGC Assembly was never meant for such mundane tasks (indeed we are printing a number)
# Description: Displays the number 08101986 (my Birthday) on the DSKY.
# Start of the program
COUNT* DisplayNumber.agc
# CONSTANTS AND VARIABLES
NumberSignal OCT 03411 # Octal representation of 08101986
DSKYChannel EQUALS 10 # DSKY Channel
# ACTUAL ROUTINE
CA NumberSignal # Load the number signal into the accumulator
EXTEND # Extend the instruction
WRITE DSKYChannel # Send accumulator data to the DSKY
TC ENDPGM # End the program
# End of program
END
Now, diving into the treasure trove that is the Apollo 11 GitHub repository, there lies a file named THE_LUNAR_LANDING.agc
in the Luminary099
directory. This file is the gatekeeper to understanding the moon's descent, storing the code for the P63 Lunar Landing Braking Phase among other critical mission phases.
As our astronauts approached the moon, ready to initiate the landing sequence, a simple command triggered the P63 Lunar Landing Braking Phase, setting in motion a meticulously crafted routine designed to guide the Lunar Module to a safe landing.
Chapter 3: Description of Astronaut and AGC interactions during the descent
To help me with this chapter, I reviewed Apollo 11 Mission transcript and this NASA Video and try to combine those moments with the code of the Lunar landing
As the Lunar Module (LM) "Eagle" orbited the Moon with astronauts Neil Armstrong and Buzz Aldrin on board. Houston and the astronauts were engaged in a meticulous review of the descent plan, ensuring every system was primed for the task ahead.
Houston: “Eagle, Houston. We read you now. You're GO for PDI. Over.”
Armstrong: "Roger, understand."
The confirmation of "GO for PDI" from Houston was more than a technical go-ahead; it was a collective affirmation of readiness to transition from orbital flight to the descent towards the lunar surface.
Columbia: “Coming up on 1 minute to TIG, Neil. How's it looking?”
Armstrong: “Pretty good.”
The stage was set. The astronauts reviewed their checklists one last time, rechecked the systems, and with a shared breath of anticipation, prepared to input the commands that would initiate the descent procedure. The discourse with Houston provided a structured cadence, within which the rhythmic dance of man, machine, and mission was about to unfold against the vast, silent backdrop of space.
3.1 Setting the Stage: The Descent Commences
The descent to the lunar surface was a mission-critical phase. Our astronauts, Armstrong and Aldrin, found themselves steering towards the unknown, with only their training, Houston's guidance, and the Apollo Guidance Computer (AGC) as their allies.
The air crackled with tension as the communication between Apollo 11 and Houston set the pace for this phase. With a go from Houston, Armstrong and Aldrin initiated the descent sequence via the DSKY (Display and Keyboard Unit), the interface to the AGC.
Houston: "You are Go for powered descent."
Armstrong: "Roger, understand, Go for powered descent."
As Armstrong keyed in Verb 37 Noun 63 on the DSKY
the AGC was instructed to transition to a new phase of the mission—the descent phase.
COUNT* PHASCHNG
PHASCHNG TC PHASCHNG
OCT 04024
In this code, PHASCHNG
(short for "Phase Change.") is a routine that tells the AGC, "Hey, it's time to switch gears and get ready for the descent phase."
COUNT* PHASCHNG
: This line is specifying a memory location labeledPHASCHNG
.COUNT
is a directive used in AGC assembly language to set the location counter to a specific address, in this case, the address labeledPHASCHNG
. This is essentially marking the start of a new section of code.PHASCHNG TC PHASCHNG
: In this line,PHASCHNG
is the label for this instruction.TC
stands for "Transfer Control", which is an instruction that tells the AGC to jump to another part of the program specified by the address followingTC
. In this case, it's telling the AGC to jump to the instruction at thePHASCHNG
address, essentially creating a loop.OCT 04024
: This line is specifying an octal (base 8) value04024
. In the AGC, octal was often used for representing data. The meaning of this value would depend on the context in which it's used within the AGC program.
When the astronauts inputted Verb 37 Noun 63 into the DSKY, the AGC would interpret it, and the corresponding pre-programmed routine in the AGC's software would be executed to carry out the required action for that phase change.
From the Virtual AGC documentation for flying with the Virtual AGC.
Verb 37 : From the documentation, Verb 37 is denoted as "Change program," which instructs the AGC to switch to a different program or routine.
Noun 63 : Delta-altitude, altitude rate and altitude. This phase is crucial for reducing the spacecraft's velocity as it approaches the lunar surface.
Combining these, the command Verb 37 Noun 63 could imply a change in the program to initiate or engage with the "Braking Phase" of the lunar descent.
3.2 The Eagle Approaches: Code in Action
When Aldrin inputted Verb 16 Noun 68 on the DSKY, he was essentially asking the AGC to display the rate at which they were descending towards the moon.
Verb 16: In the context of the DSKY, a Verb represents an action or command. Verb 16 is typically associated with monitoring or displaying a particular value or set of values.
Noun 68: A Noun specifies the data or object upon which the Verb is to act. Noun 68 represent downrange distance, time-to-go in braking phase (minutes and seconds), velocity. within the AGC software.
COUNT* BURNBABY
BURNBABY CAF PHASCHNG
TS PHASCHNG
The routine "BURNBABY" in the Apollo 11 Guidance Computer code is associated with firing the Lunar Module's engine
COUNT* BURNBABY
:The
COUNT*
statement is a directive to the assembler. It’s used here to specify a location counter, essentially telling the assembler where to place the following code in memory.BURNBABY
is a label that identifies the location of this block of code. It’s akin to a name tag on a suitcase, allowing other parts of the program to find and reference this particular block.
BURNBABY CAF PHASCHNG
:Here’s where the action begins.
CAF
stands for "Clear and Add", a command that clears the accumulator (a special register used for arithmetic operations) and then adds the value ofPHASCHNG
to it.PHASCHNG
is a constant or a memory location (its name suggesting a phase change). It holds a value that, when added to the accumulator, sets up the desired conditions for the engine burn.
TS PHASCHNG
:TS
stands for "Transfer to Storage", an instruction that takes the current value in the accumulator and stores it in the specified location, in this case, back intoPHASCHNG
.This line essentially updates the value of
PHASCHNG
with the new value from the accumulator, reflecting the conditions for the engine burn.
This snippet illustrates a straightforward, yet consequential, operation: preparing the system for an engine burn by updating a particular value (PHASCHNG
) in memory.
Now, when Buzz Aldrin inputted Verb 16 Noun 68 on the DSKY, he was essentially instructing the AGC to display the descent rate, as Verb 16 is associated with monitoring or displaying values, and Noun 68 relates to critical descent parameters. This interaction between astronaut and machine, facilitated by a well-defined and executed code, ensured the crew stayed informed and in control during this crucial phase of the mission.
Fun Fact: The name of the Apollo 11 Guidance Computer routine "BURNBABY" has an intriguing backstory. It traces its roots to the 1965 Los Angeles riots, inspired by the iconic phrase "Burn, baby! BURN!" used by charismatic disc jockey Magnificent Montague while spinning the hottest records of the time. This tidbit was shared by one of the routine's authors, Don Eyles, during a gathering of AGC developers celebrating the 40th anniversary of the first moonwalk
Houston: "Descent engine command override, off."
Armstrong: "Engine arm is off."
Houston: "Roger. Copy."
3.3 The Final Moments: Touchdown
As the lunar surface neared
COUNT* BURNBABY
TOUCHDWN CAF FOUR # signify touchdown
COUNT* BURNBABY
acts as a memory location directive.TOUCHDWN
is a label, identifying this block of code.CAF FOUR
clears the accumulator and adds the value ofFOUR
to it, which likely represents a constant with a value of 4.This operation updates the accumulator to signify a touchdown event, akin to how
BURNBABY
routine was used earlier in the descent phase to prepare for engine burn, illustrating how different routines were triggered to manage various phases of the lunar landing.
this transition wasn't initiated by Armstrong or Aldrin directly. Instead, it was triggered automatically by the AGC based on the lunar module's sensors detecting contact with the lunar surface. The AGC was programmed to transition through various phases of the landing autonomously, reacting to sensor data and executing the appropriate routines to manage the descent and touchdown on the moon's surface.
04 06 45 52 LMP (EAGLE)
413 is in.
04 06 45 57 CC
We copy you down, Eagle.
04 06 45 59 CDR (TRANQ)
Houston, Tranquility Base here.
04 06 46 04 CDR (TRANQ)
THE EAGLE HAS LANDED.
04 06 46 06 CC
Roger, Tranquility. We copy you on the ground. You got a bunch of guys about to turn blue. We're breathing again. Thanks a lot.
04 06 46 16 CDR (TRANQ)
Thank you.
04 06 46 18 CC
You're looking good here.
04 06 46 23 CDR (TRANQ)
Okay. We're going to be busy for a minute.
04 06 46 25 LMP (TRANQ)
MASTER ARM, ON. Take care of the ... I'll get this ...
04 06 46 38 LMP (TRANQ)
Very smooth touchdown.
This transcript captures the real-time communication between the astronauts and Mission Control during the historic lunar landing.

Chapter 4: The Legacy: AGC's Impact on Modern Computing
The Apollo Guidance Computer (AGC) marked a significant milestone in the evolution of computing. This piece of engineering, developed in the 1960s, showcased the potential of digital computers in executing critical real-time, reliable calculations that were crucial for space exploration. The design principles, the rigorous testing and verification processes, and the innovative software-hardware integration of the AGC laid a strong foundation for the subsequent advancements in computing technology.
The AGC's triumph in guiding Apollo 11 to the moon and back underscored the critical role of software in complex systems.
Moreover, the AGC was a testament to the power of human-machine collaboration. It demonstrated how well-designed systems could augment human capabilities, enabling astronauts to perform precise navigational calculations and make informed decisions during the mission.
Furthermore, the modularity and reliability of the AGC's hardware and software architectures inspired a generation of computer scientists and engineers. The principles of fault tolerance, error detection and correction, and systematic testing that were inherent to the AGC's design are now staples in the field of computer science.
The AGC's legacy extends beyond its technical accomplishments. It symbolizes a monumental human achievement and stands as a testament to the spirit of innovation, collaboration, and exploration
Chapter 5: Margaret Hamilton: The Woman Who Took Us to the Moon
Margaret Hamilton's journey began long before Apollo 11. Born in 1936, she dove into the world of software at a time when the term "software engineering" didn't even exist.
Margaret Hamilton coined the term "software engineering" during her work on the Apollo missions. She felt that software development was as complex and critical as hardware engineering, and thus deserved the same level of professional recognition. By introducing this term, Hamilton helped elevate the field, emphasizing the importance of a systematic, engineering-based approach to software development, which was crucial in gaining respect and resources for software activities, eventually shaping the profession into what it is today.
Her work at MIT Instrumentation Laboratory was groundbreaking. She led the team that developed the on-board flight software for Apollo missions. Among her remarkable contributions was the software capable of detecting system errors and recovering from a computer crash.
Margaret Hamilton and her team developed a robust error detection and recovery system for Apollo 11's on-board flight software. Through a system called "asynchronous executive," her software could prioritize tasks based on their importance. When an unexpected error occurred during Apollo 11's descent, causing system overloads, Hamilton's software automatically shed less critical tasks to ensure the computer could continue managing the descent and landing processes. This real-time error detection and recovery showcased an advanced level of software reliability and automation that was groundbreaking at the time.
Hamilton's legacy continues to inspire. Her story is a lesson in vision, resilience, and the profound impact one individual can have on the world.
Conclusion: Cheers to Code, Cosmos, and Birthdays
Writing this post has been a blast, and what a way to gear up for my birthday! Diving into Apollo 11’s code and reading all the trancript took me on a journey back in time, and I couldn’t have asked for a better way to celebrate.
Bonus Chapter: A Snapshot of History

Attached is a screenshot of the transcript between Houston and Apollo 11. This dialogue shows how the world was tuned in, celebrating the mission. Reading it, you can almost feel the global excitement. It's a peek into a time when the world united to witness humans stepping on the moon. It's these dialogues that help us relive those iconic moments, understand the camaraderie, the humor, and the anticipation that encapsulated the mission, making the exploration of Apollo 11's code even more profound.
also here is a version of the virtual AGC ported to javascript ASM using emscripten, totally all in the browser : https://svtsim.com/moonjs/agc.html
a fun fact to add about the hand woven memory. It was done by a team of purely women, seamstresses specifically and NASA wanted the most experienced such delicate work in a hurry which normally meant those with decades of experience.
The internal codename NASA used was LOL memory, Little Old Lady memory.