The Lunar Landing

Page 789 of the actual Luminary099 assembly listing, photographed at the MIT Museum by Paul Fjeld for the Virtual AGC project. Three famous comments on one page — “PLEASE CRANK THE SILLY THING AROUND,” “SEE IF HE’S LYING,” and “OFF TO SEE THE WIZARD… BURNBABY.”
Two source files contain the code that actually landed on the Moon: THE_LUNAR_LANDING.agc (the P63 braking phase initialization) and LUNAR_LANDING_GUIDANCE_EQUATIONS.agc (the guidance math and phase control logic). Together, they constitute the most consequential guidance software ever executed.
The Phases of Descent
Section titled “The Phases of Descent”The lunar landing was not a single maneuver but a sequence of phases, each managed by a different program:
| Phase | Program | Purpose |
|---|---|---|
| Braking | P63 | High-thrust deceleration from orbital velocity |
| Approach | P64 | Visibility phase with landing site redesignation |
| Vertical | P65 | Final vertical descent |
| Rate of Descent | P66 | Manual throttle control (ROD mode) |
| Manual | P67 | Full manual attitude and throttle |
The variable WCHPHASE tracked which phase was active:
WCHPHASE = -1during the ignition algorithmWCHPHASE = 0during braking (P63)WCHPHASE = 1during approach (P64)WCHPHASE = 2during vertical descent (P65/P66/P67)
FLAGORGY — Dionysian Flag Waving
Section titled “FLAGORGY — Dionysian Flag Waving”P63 begins with what may be the most memorably-labeled initialization block in the entire codebase:
FLAGORGY TC INTPRET # DIONYSIAN FLAG WAVING CLEAR CLEAR NOTHROTL REDFLAG CLEAR SET LRBYPASS MUNFLAG CLEAR CLEAR P25FLAG # TERMINATE P25 IF IT IS RUNNING. RNDVZFLG # TERMINATE P20 IF IT IS RUNNING
“Dionysian flag waving” — Dionysus being the Greek god of wine, ritual madness, and ecstasy. The programmer is comparing the frenzy of flipping a dozen configuration flags to a Bacchanalian revel. The label FLAGORGY drives the point home.
What these flags actually do is serious: they configure the throttle, enable the landing radar, activate lunar gravity modeling, and shut down any rendezvous or navigation programs that might compete for computer time during descent. Every flag cleared here is one less thing that can interfere with the landing.
PLEASE CRANK THE SILLY THING AROUND
Section titled “PLEASE CRANK THE SILLY THING AROUND”After the attitude maneuver and before initiating the descent burn, P63 needs the landing radar antenna rotated to position 1. If it is not already there, the code puts up a display asking the astronaut to do it manually:
P63SPOT3 CA BIT6 # IS THE LR ANTENNA IN POSITION 1 YET EXTEND RAND CHAN33 EXTEND BZF P63SPOT4 # BRANCH IF ANTENNA ALREADY IN POSITION 1 CAF CODE500 # ASTRONAUT: PLEASE CRANK THE TC BANKCALL # SILLY THING AROUND CADR GOPERF1 TCF GOTOPOOH # TERMINATE TCF P63SPOT3 # PROCEED SEE IF HE'S LYING
The comments read like stage directions: “ASTRONAUT: PLEASE CRANK THE SILLY THING AROUND.” And after the astronaut presses PROCEED, the code checks again — “SEE IF HE’S LYING.” If the antenna still is not in position 1, the display comes back.
OFF TO SEE THE WIZARD
Section titled “OFF TO SEE THE WIZARD”With the antenna in position and the landing radar initialized, P63 hands off to the ignition routine:
P63SPOT4 TC BANKCALL # ENTER INITIALIZE LANDING RADAR CADR SETPOS1 TC POSTJUMP # OFF TO SEE THE WIZARD... CADR BURNBABY
“Off to see the wizard…” — and the wizard is BURNBABY, the master ignition routine. The POSTJUMP / CADR pair is a bank-switching call, because BURNBABY lives in a different memory bank. The ellipsis in the comment suggests the programmer was well aware of the drama of what comes next.
GUILDENSTERN — The Auto-Modes Monitor
Section titled “GUILDENSTERN — The Auto-Modes Monitor”Deep in the guidance equations, the auto-modes monitor carries a name from Shakespeare:
#*******************************************************************# GUILDENSTERN: AUTO-MODES MONITOR (R13)#*******************************************************************
# HERE IS THE PHILOSOPHY OF GUILDENSTERN: ON EVERY APPEARANCE OR# DISAPPEARANCE OF THE MANUAL THROTTLE DISCRETE TO SELECT P67 OR P66# RESPECTIVELY: ON EVERY APPEARANCE OF THE ATTITUDE-HOLD DISCRETE TO# SELECT P66 UNLESS THE CURRENT PROGRAM IS P67 IN WHICH CASE THERE# IS NO CHANGEGuildenstern, from Hamlet, is the courtier who watches and reports. Here, the subroutine watches the discrete input channels for changes in the astronaut’s control mode — switching between automatic (P65/P66) and manual (P67) flight. It runs on every guidance cycle, monitoring the hand controller and throttle switches.
The redesignation monitor uses similarly operatic variable names: ELVIRA and ZERLINA — both characters from Mozart operas (Don Giovanni and Die Entfuhrung aus dem Serail, respectively). These are debounce counters for the redesignation hand controller inputs.
TEMPORARY, I HOPE HOPE HOPE
Section titled “TEMPORARY, I HOPE HOPE HOPE”During the initialization of P66 (the rate-of-descent mode), there is this:
CAF TWO # WCHPHASE = 2 ---> VERTICAL: P65,P66,P67 TS WCHPHOLD TS WCHPHASE TC BANKCALL # TEMPORARY, I HOPE HOPE HOPE CADR STOPRATE # TEMPORARY, I HOPE HOPE HOPE
The STOPRATE call zeroes out the attitude rates before switching to rate-of-descent control. The comment betrays the programmer’s anxiety about a workaround that might have become permanent. In software engineering, there is nothing more permanent than a temporary fix — and this one made it all the way to the Moon.
NUMERO MYSTERIOSO
Section titled “NUMERO MYSTERIOSO”In the guidance-stable member transformation matrix computation (CGCALC), a cryptic constant appears:
STODL CG TTF/8 DMP* VXSC GAINBRAK,1 # NUMERO MYSTERIOSO ANGTERM
“Numero mysterioso” — the mysterious number. GAINBRAK is a gain constant for the braking phase guidance. The programmer apparently could not derive it from first principles and either received it from analysis or tuned it empirically. Either way, it worked.
The Guidance Equation
Section titled “The Guidance Equation”The main guidance equation computes the commanded acceleration vector (ACG) from the current state errors:
# AS PUBLISHED --# ___ __ ___ __# ___ ___ 6(VDG + VG) 12(RDG - RG)# ACG = ADG + ----------- + ------------# TTF (TTF)(TTF)This is a quadratic guidance law. RDG and VDG are the desired (target) position and velocity; RG and VG are the current position and velocity in guidance coordinates; ADG is the desired acceleration; and TTF is time-to-go to the target. The equation commands an acceleration that drives both position and velocity errors to zero at the target time.
The implementation scales everything by factors of 8 for numerical stability in the AGC’s fixed-point arithmetic:
# AS HERE PROGRAMMED --# ___ __# 3 (1/4(RDG - RG) ___ __)# - (------------- + VDG + VG)# ___ 4 ( TTF/8 ) ___# ACG = ---------------------------- + ADG# TTF/8All the ASCII art in the comments was hand-formatted to fit the 80-column printout width. These equations were computed every two seconds during descent — a cycle time that the Executive had to protect at all costs.
ROOTPSRS — Allan Klumpp’s Root Finder
Section titled “ROOTPSRS — Allan Klumpp’s Root Finder”The TTF (time-to-free-fall) computation requires finding the root of a polynomial, and the code credits its author:
# ***********************************************************************************# DOUBLE PRECISION ROOT FINDER SUBROUTINE (BY ALLAN KLUMPP)# ***********************************************************************************Klumpp’s ROOTPSRS uses Newton’s method to converge on the root of a power series. It gives up after eight iterations:
CA MODE MASK BIT4 # KLUMPP SAYS GIVE UP AFTER EIGHT PASSES CCS ABADROOT TC RETROOT“KLUMPP SAYS GIVE UP” — a direct attribution in the comments. The routine is used to solve the cubic time-to-go equation that determines when the LM will reach the target altitude if it follows the current guidance commands.
Landing Confirmation
Section titled “Landing Confirmation”After the LM touches down, P68 handles the post-landing state:
LANDJUNK TC PHASCHNG OCT 04024
INHINT TC BANKCALL # ZERO ATTITUDE ERROR CADR ZATTEROR
TC BANKCALL # SET 5 DEGREE DEADBAND CADR SETMAXDBThe label LANDJUNK suggests the programmer’s view of the post-landing housekeeping — after the intensity of the descent, this is the mundane cleanup. It zeros out the attitude errors, sets a wide deadband so the RCS jets stop firing, computes the actual landing coordinates, and displays them to the crew:
CAF V06N43* # ASTRONAUT: NOW LOOK WHERE YOU ENDED UP TC BANKCALL CADR GOFLASH
“NOW LOOK WHERE YOU ENDED UP.” After the most complex automated guidance sequence ever attempted, the computer essentially shrugs and says: Well, here you are.