Lorenzo Vainigli

Software developer, passionate about programming

The code that took us beyond our frontiers

20 July 2019
Assembly History
5 min.

Questo articolo รจ disponibile in italiano

Half a century after Neil Armstrong’s venture, the source codes of Apollo 11 have been published online

Today is exactly 50 years since the day the first man set foot on the Moon, 20 July 1969. “That’s one small step for man, one giant leap for mankind” is the phrase that continues to echo in our lives, but how much computer science has helped man to reach the Earth’s satellite? It was simply fundamental. Let’s try to better understand what tools the astronauts had at their disposal.

The Apollo Guidance Computer

There is a Github repository which contains part of the source codes for the Apollo Guidance Computer, i.e. the control center for the comman module and the lunar module (cover photo). The code is the original one kept in paper form in the museum of the MIT.
Before you take a look at it, let’s consider the technical specifications of the AGC.

  • Processor based on Discrete IC RTL at 2.048 MHz.
  • 4 KB of magnetic core RAM consisting of 2,048 words of 16 bits (one of them for the parity bit).
  • 72 KB core rope type ROM memory composed of 36,864 words.
  • Energy consumption: 55W.
  • Weight: 32 kg.
  • Dimensions: 61 x 32 x 17 cm.

In the years when there was enthusiasm because computers were able to stay “only” in a room, this device was futuristic. His performance were then achieved by the personal computers of the end of the ’70s, like Apple II.

The AGC was composed of 4 main registers: the accumulator (A), the program counter (Z), the register for the return address or for the rest of a division (Q) and the register for the lower product of multiplications (LP). There were also 23 other registers, 4 of which were part of a group IN (input) and 4 of a group OUT (output).

The command interface

DSKY Interface

The AGC had its own command interface: the DSKY. On one hand there were a series of lights showing the status of the computer, on the other a display indicating the number of the program running (if any); verbs and nouns, i.e. the two input parameters that the astronauts could enter, and three output values. At the bottom there was a numeric keyboard with dedicated buttons.

The programs available on the computer were identified by numbers and a program would start when its number was entered. Below there are tables with program numbers, verbs and nouns.

The source code

Margaret Hamilton and the source code written for the Apollo Guidance Computer.

The programming language used to program the computer of Apollo 11 is a version of assembly developed ad-hoc by a group of scientists at MIT directed by Margaret Hamilton, which has become one of the most influential women in the history of computer science.
Among the many and complex instructions we can mention some of them that we will see are not far from the general instructions of assembly.

  • TC (Transfer Control): inconditional jump tipically used for procedure calls.
  • CCS (Count, Compare, Skip): complex command used for generating cycles; it works with register A.
  • INDEX: retrieves data from an address passed by parameter; used for array and look-ups.
  • RESUME: particular case of INDEX with parameter 25. It allowed to resume the execution after an interrupt.
  • XCH (Exchange): a kind of hybrid between load and store, it switches the content of the address specified with the register A. If the memory is read-only, this command only load the datum into A.
  • CS (Clear and Subtract): it loads A the value obtained complementing all bits of the datum stored in the memory address passed as parameter.
  • TS (Transfer to Storage): it performs a store of the content of A and detects overflow errors.
  • AD (Add): it adds to A the content of the specified address.
  • MASK: logic and between the content of the memory address and A; stores the result in A.
  • MP (Multiply): performs a multiplication between the content of the memory address and A, the stores the less significant bits of the result in LP e and the most significant bits in A.
  • DV (Divide): division between the content of the memory address and A. Stores the quotient in A and the remainder in Q.
  • SU (Subtract): Subtracts from A the complement (bit by bit) of the content of the memory address.

We can see that as parameters to these commands should be passed only memory addresses and the register A is fundamental for each of them.
There are other types of instructions, even more complicated, which are reported on the documentation.

In conclusion

Languages assembly-based are now part of the historical archives of computer science and have given way to the most versatile and powerful high-level languages. Today it is unthinkable to write an entire program in assembly, unless it is something similar to Hello World; in some particular cases, however, assembly can still be useful, if you want to manage registers and memory addresses.
It may then be a moment to remember that, only 50 years ago, the state of the art in this field was very far from that of today, but not for this reason unable to leave its mark in the history of mankind.

If you want to know more about you can read the Introduction to the Apollo Guidance Computer, you can also download a simulator of the two modules (command and lunar) from this site.
Here the same simulator has been made in javascript.

Who knows, which code will one day take us to Mars?


Apollo Guidance Computer on Wikipedia EN
Virtual AGC

Lorenzo Vainigli

Android developer and passionate about computers and technology since I was a child.
I have a master's degree in Computer Science obtained at the University of Bologna.
I like astronomy ๐ŸŒŒ and Japanese culture โ›ฉ๏ธ.
Here I tell more about myself.