Commanded by Alan Shepard, the only original Mercury astronaut to make it to the Moon on an Apollo mission, Apollo 14 was a reflight of Apollo 13's abandoned lunar landing plan. Accompanied by Lunar Module Pilot Ed Mitchell and Command Module Pilot Stu Roosa, Shepard's target was the Fra Mauro highlands, a hilly area near the lunar equator and just south of the giant crater Copernicus. Likely created from the ejecta thrown out when Mare Imbrium was formed, the Fra Mauro site was thought to potentially contain material from deep inside the Moon that could shed light on our companion satellite's origin.

In the eight months since the harrowing flight of Apollo 13, engineers made several changes to the spacecraft to reduce the chance of another explosion happening. To help ensure that the crew could make it home if another emergency occurred, an additional oxygen tank and battery were added. The unplanned pause also allowed time for some software updates to be added to the lunar module computer; a particularly welcome addition was the ability of the computer to recognize changes in the height of the surface during the approach to the landing site. With this new capability, the computer would not be confused by the undulating terrain as the vehicle headed toward landing.

What is past is prologue

In the afternoon of January 31, 1971, the flight thundered away from the Kennedy Space Center on its Saturn V launch vehicle after only a brief 40 minute hold for weather. After restarting the S-IVB third stage for trans-lunar injection (TLI), the command module Kitty Hawk and her crew were on their way to the Moon.

A very serious problem cropped up almost immediately after TLI, as Kitty Hawk attempted to dock with the mission's lunar module, Antares. Fingernail-sized latches on the docking probe used to connect the command module to the lunar module failed to catch, and the two spacecraft were unable to dock. Only after repeated attempts was Kitty Hawk able to capture and securely attach Antares. Afterwards, the S-IVB was sent on its way to a lonely but spectacular death and the combined Apollo 14 spacecraft continued the voyage to Fra Mauro.

The four days in transit and the time spent in lunar orbit were uneventful—or at least as uneventful as a flight to the Moon could be. Insertion into lunar orbit occurred at about 82 hours into the flight. To conserve precious fuel in the LM, the combined spacecraft lowered its orbit to a nine mile (about 14.5 kilometers) periapsis several hours later. Preparations for the descent started the next day, with the activation and checkout of the LM.

However, less than four hours before the scheduled landing, controllers noticed that according to the indications on their consoles in Mission Control, the LM's Abort pushbutton appeared to have been pressed. When asked via radio, Shepard confirmed that no one on board Antares had pressed the Abort button—which meant there was a short-circuit or other electrical issue somewhere inside the LM's complicated guts.

This was potentially a mission-ending problem: if the button was pressed and the engine was firing, the LM would immediately begin its abort procedure as soon as the lunar descent started, making a landing impossible.

Under hard time pressure, the ground had to quickly figure out what was wrong and devise a workaround. What they came up with was the most brilliant computer hack of the entire Apollo program, and possibly in the entire history of electronic computing.

To explain exactly what the hack was, how it functioned, and the issues facing the developers during its creation, we need to dig deep into how the Apollo Guidance Computer worked. Hold onto your hats, Ars readers—we're going in.

The Apollo Guidance Computer laid bare

It’s common to find that the AGC is often described as a mere calculator, or compared to a controller chip suitable for a watch or microwave. Looking at your watch, it tells the time and little else. The chip that drives the microwave blindly starts and stops the magnetron to heat expired Kung Pao chicken. In these devices, there is a very limited interaction with the surrounding hardware, no sophisticated computation, and no decision-making of any note.

I do not think it means what you think it means Technology terms usually have a very short lifetime, and those used a half-century ago are especially vulnerable. To help with these explanations, I’ve occasionally fallen into phrases and terms that are more familiar to contemporary system and software practitioners. Phrases such as “ROM,” “dispatching work," “virtual machine,” and others reflect concepts that are familiar today, but were not in use in the 1960s. They are used to convey the intention and spirit of the ideas at the time.

In describing a "computer," one expects that the system would include the abilities we attribute to contemporary computers—the ability to run several programs at once, for example, or to present a simple yet intuitive interface, to control a wide variety of devices, and to gracefully recover from application errors. “Ha!” you might exclaim, “I carry a computer like that in my pocket!”

The idea of such capabilities being available nearly 60 years ago stretches credulity, but the Apollo Guidance Computer had these features and more. An interpreter to process “virtual” machines, similar to Java byte code? Check. The ability for remote data updates? Yup. Given all of these capabilities and more, it’s quite reasonable to argue that the AGC compares favorably with a modern smartphone. Yes, the AGC is slower and has far less memory, but that is only due to its unfortunate timing at birth, being at the wrong end of the Moore’s Law curve.

Although the processor at approximately 80,000 instructions per second was not especially fast, it is impossible to overemphasize the impact that its scarce memory had on AGC software developers. Consider the limits the programmers were under: all the software for the flight to the Moon and back had to fit in 36K words (15 bits long, plus 1 bit for parity) of read-only core rope memory. As “bytes” were not a concept in the AGC, all 15 bits of a word were accessed at once with no easy way to break the word into smaller divisions.

Bits and Bytes and Words, oh my! If you ask any contemporary computer person what the basic unit of data in computing is, the answer is instantaneous: the lowly byte. Eight bits of digital data all wrapped up in a single, neat, addressable package. If you ask any contemporary computer person what the basic unit of data in computing is, the answer is instantaneous: the lowly byte. Eight bits of digital data all wrapped up in a single, neat, addressable package. But this was not always the case. Early generations of computers opted for having the smallest addressable unit as the “word.” Word lengths varied wildly, from 12 bits on the PDP-8 to 36 bits on Univac mainframes. Not breaking the word down further allowed lots of bits to be accessed without having to increase the size of the address field of an instruction. As such, individual “bytes” did not exist. Accessing individual fields (such as an ASCII character) often required additional instructions to mask or shift the data out.

Secondary storage was not an option: disk units, then the size of washing machines, could not even fit in the spacecraft. Tape storage, while a reliable and viable option, was considered far too late in the development cycle to be included in any designs. The AGC's software was entirely contained within core-rope modules housed inside the AGC itself, a 70lb (about 32kg) box measuring 61cm long, 32cm wide, and 17cm tall.

In addition to the 36k words of read-only memory for the core programming, the AGC had a trivial 2k words of RAM—necessary for the operating system, process management, recovery, and global variables for all mission phases. That’s it. Shoehorned amongst this meager amount of RAM were dedicated memory areas used by application programs: the software that performed the guidance and navigation tasks, landing on the Moon, or rendezvous. Basic programs were each allowed a whopping seven words for temporary variables. And no, that’s not a misprint.

With these constraints in mind, it’s easy to be cynical when facing the task of installing the latest multi-gigabyte application on our laptops.

Listing image by Frank O'Brien / Aurich Lawson