Skip to content
0 / 17
Pre-launch Review

The Lunar Landing

Scanned page 789 of the Luminary099 assembly listing showing THE LUNAR LANDING. Three famous comments visible: PLEASE CRANK THE SILLY THING AROUND, SEE IF HE'S LYING, and OFF TO SEE THE WIZARD... BURNBABY.

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 lunar landing was not a single maneuver but a sequence of phases, each managed by a different program:

PhaseProgramPurpose
BrakingP63High-thrust deceleration from orbital velocity
ApproachP64Visibility phase with landing site redesignation
VerticalP65Final vertical descent
Rate of DescentP66Manual throttle control (ROD mode)
ManualP67Full manual attitude and throttle

The variable WCHPHASE tracked which phase was active:

  • WCHPHASE = -1 during the ignition algorithm
  • WCHPHASE = 0 during braking (P63)
  • WCHPHASE = 1 during approach (P64)
  • WCHPHASE = 2 during vertical descent (P65/P66/P67)

P63 begins with what may be the most memorably-labeled initialization block in the entire codebase:

Luminary099/THE_LUNAR_LANDING.agc
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
Machine instructions — woven into rope Comments — woven into history

“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.

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:

Luminary099/THE_LUNAR_LANDING.agc:239-249
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
Machine instructions — woven into rope Comments — woven into history

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.

With the antenna in position and the landing radar initialized, P63 hands off to the ignition routine:

Luminary099/THE_LUNAR_LANDING.agc:251-255
P63SPOT4	TC	BANKCALL	# ENTER     INITIALIZE LANDING RADAR
	CADR	SETPOS1

	TC	POSTJUMP	# OFF TO SEE THE WIZARD...
	CADR	BURNBABY
Machine instructions — woven into rope Comments — woven into history

“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.

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 CHANGE

Guildenstern, 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.

During the initialization of P66 (the rate-of-descent mode), there is this:

Luminary099/LUNAR_LANDING_GUIDANCE_EQUATIONS.agc:175-180
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
Machine instructions — woven into rope Comments — woven into history

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.

In the guidance-stable member transformation matrix computation (CGCALC), a cryptic constant appears:

Luminary099/LUNAR_LANDING_GUIDANCE_EQUATIONS.agc
STODL	CG
		TTF/8
	DMP*	VXSC
		GAINBRAK,1	# NUMERO MYSTERIOSO
		ANGTERM
Machine instructions — woven into rope Comments — woven into history

“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 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/8

All 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.

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 A
BADROOT 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.

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 SETMAXDB

The 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:

Luminary099/THE_LUNAR_LANDING.agc
CAF	V06N43*		# ASTRONAUT:  NOW LOOK WHERE YOU ENDED UP
	TC	BANKCALL
	CADR	GOFLASH
Machine instructions — woven into rope Comments — woven into history

“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.