
Source code for the Apollo 11 Guidance Computer - carljoseph
http://www.ibiblio.org/apollo/listings/Comanche055/
======
cramerica
There are some pretty great comments in here:

ALARM_AND_ABORT.agc -
[http://www.ibiblio.org/apollo/listings/Comanche055/ALARM_AND...](http://www.ibiblio.org/apollo/listings/Comanche055/ALARM_AND_ABORT.agc.html)

    
    
        TC       WHIMPER    -1   #  YES.  DON'T DO POODOO.  DO BAILOUT.
    

From the Guidance Computer Data Cards
-[http://www.ibiblio.org/apollo/CMC_data_cards_15_Fabrizio_Ber...](http://www.ibiblio.org/apollo/CMC_data_cards_15_Fabrizio_Bernardini.pdf)

"POODOO abort, does software restart (ENEMA) and "GO TO POOH" (flashing Verb
37) unless "AVERAGE G" is running then only software restart"

From THE_LUNAR_LANDING.agc -
[http://www.ibiblio.org/apollo/listings/Luminary099/THE_LUNAR...](http://www.ibiblio.org/apollo/listings/Luminary099/THE_LUNAR_LANDING.agc.html)

    
    
        033911,000064: 32,3017    06037        FLAGORGY        TC       INTPRET      #  DIONYSIAN FLAG WAVING
    
    
        034090,000243: 32,3241    13247        BZF      P63SPOT4               #  BRANCH IF ANTENNA ALREADY IN POSITION 1
        034091,000244: 
        034092,000245: 32,3242    33254        CAF      CODE500                #  ASTRONAUT:     PLEASE CRANK THE
        034093,000246: 32,3243    04616        TC       BANKCALL               #                 SILLY THING AROUND
        034094,000247: 32,3244    20623        CADR     GOPERF1                               
        034095,000248: 32,3245    16001        TCF      GOTOP00H               #  TERMINATE
        034096,000249: 32,3246    13235        TCF      P63SPOT3               #  PROCEED        SEE IF HE'S LYING
    
    
        034101,000254: 32,3251    04635        TC       POSTJUMP               #  OFF TO SEE THE WIZARD ...
        034102,000255: 32,3252    74126        CADR     BURNBABY

~~~
daveslash
I like the note at the top of
[http://www.ibiblio.org/apollo/listings/Luminary099/BURN_BABY...](http://www.ibiblio.org/apollo/listings/Luminary099/BURN_BABY_BURN
--MASTER_IGNITION_ROUTINE.agc.html)

 _At the get-together of the AGC developers celebrating the 40th anniversary
of the first moonwalk, Don Eyles (one of the authors of this routine along
with Peter Adler) has related to us a little interesting history behind the
naming of the routine.

It traces back to 1965 and the Los Angeles riots, and was inspired by disc
jockey extraordinaire and radio station owner Magnificent Montague.
Magnificent Montague used the phrase "Burn, baby! BURN!" when spinning the
hottest new records. Magnificent Montague was the charismatic voice of soul
music in Chicago, New York, and Los Angeles from the mid-1950s to the
mid-1960s._

------
dang
The source code is here:
[http://www.ibiblio.org/apollo/listings/Comanche055/](http://www.ibiblio.org/apollo/listings/Comanche055/).
We changed the url to the top-level page which provides an overview.

Edit: see subthread below.

~~~
raldi
Hmm.

To me, the appeal of the original link was that, with one click, I could see
the entire annotated-with-original-comments source of any part of the AGC.
That was really exciting. A simulator (to me at least) is a lot less
interesting ... and it's certainly an objectively very different kind of
thing. (I for one wouldn't have even bothered clicking the current headline if
I hadn't been looking for the original post's comments, which I had seen
earlier.)

I'm not against curation in general -- it's a crucial aspect of HN, perhaps
_the_ crucial aspect. But I do think this particular case was a bit odd.

~~~
dang
Ok, that's pretty persuasive, especially since most of the comments here are
about the code. We changed it back.

------
DanBC
Not quite sure why this links to the code, and not the top level which has a
lot more useful information (such as the simulator needed to run the code).

[http://www.ibiblio.org/apollo/](http://www.ibiblio.org/apollo/)

There's some more information here:
[http://googlecode.blogspot.co.uk/2009/07/apollo-11-missions-...](http://googlecode.blogspot.co.uk/2009/07/apollo-11-missions-40th-
anniversary-one.html)

~~~
bjackman
That's great - I actually came here to say "this is cool in an abstract way
but what the fuck am I looking at? I'd love to learn a little bit more about
the system". Turns out space folks are great at sharing knowledge!

By the way, last night I read the radio transcript from the time Neil and Buzz
exited the lunar module:
[http://www.hq.nasa.gov/alsj/a11/a11.step.html](http://www.hq.nasa.gov/alsj/a11/a11.step.html)
(that site has loads of other Apollo transcripts too). It's annotated and has
links to pics and videos. Fascinating.

~~~
mason240
>Turns out space folks are great at sharing knowledge!

I've read that one of the problems a new moon-or-beyond space program would
have is that we are so far removed from the Apollo program that all
institutional knowledge that was gained is gone because most of the engineers
on those projects have passed away.

~~~
dalke
On the other hand, how much of that institutional knowledge is still useful?
Certainly some of it is, but I think experience with the F1-B shows that new
knowledge, like 3-D printing, means that parts of the old knowledge aren't
needed.

~~~
NextPerception
I am a mechanical designer by profession and just want to point out that even
I who use a 3D printer on a daily basis can't think of any other manufacturing
method it has made completely obsolete. It is more like just another tool in
my tool belt that adds another way to make something. As with any tool it has
it's advantages and it's drawbacks and will only make sense to use it in
certain scenarios.

~~~
dalke
Certainly. That's why I said "parts" and not "all".

What I meant is described in slightly more detail at
[http://arstechnica.com/science/2013/04/how-nasa-brought-
the-...](http://arstechnica.com/science/2013/04/how-nasa-brought-the-
monstrous-f-1-moon-rocket-back-to-life/3/) , in the section "3D printing goes
to space"

> Using state of the art manufacturing processes where possible actually
> reduces cost—even if a newer manufacturing method is more expensive, the
> cost reductions gained from the design simplifications more than tip the
> scales. In particular, Dynetics and PWR are using techniques like selective
> laser melting and hot isostatic pressing (HIP) to "grow" entire complex
> engine parts out of metal powders. The Dynetics team is focusing as much as
> possible on reducing welds and joins, and therefore reducing assembly and
> manufacturing.

------
AmVess
Reading the comments is fun...and a bit scary:

    
    
        TC   BANKCALL      # TEMPORARY, I HOPE HOPE HOPE
        CADR STOPRATE      # TEMPORARY, I HOPE HOPE HOPE

------
spingsprong
[http://www.ibiblio.org/apollo/assembly_language_manual.html](http://www.ibiblio.org/apollo/assembly_language_manual.html)

Descriptions of instructions, opcodes, number encoding, etc

------
dmd
"arranged for by Deborah Douglas of the MIT Museum"

That's my wife's boss; the source material is still sitting on my wife's desk!

------
nsxwolf
Do the famous 1201 and 1202 error codes make an appearance here? My assembly
skills aren't good enough to find them, I'm afraid.

~~~
thewonderidiot
They do! They're in EXECUTIVE.agc (search for OCT 1201 and OCT 1202).

Those error codes mean "No VAC Areas" and "No Core Sets", respectively. Core
sets were the basic task control blocks, including each task's entry point,
priority, flags, some memory for temporary variables, and a few other things.
VAC (Vector Accumulator) areas were a bit more interesting. Most of the real
guidance code was not actually written in AGC assembly because it was so
primitive and limiting. So, they created the "Interpreter" (INTERPRETER.agc)
that's essentially a little virtual machine, that had its own assembly
language (complete with mathematical and vector operations). Interpreted tasks
needed more than the 7 words of temporary variables provided by the core sets,
so they also allocated these VAC areas for more storage.

Those error codes showed up on Apollo 11 because of a weird electrical power
phasing bug, essentially causing the radar to generate thousands of
"interrupts" (actually cycle stealing operations) every second. With all of
this additional work, the AGC didn't have enough time to finish its low
priority tasks. And since those tasks hadn't exited by the time they were
expected to, when the executive attempted to kick off new tasks, it found that
no core sets or VAC areas were available, and sounded those program alarms.

------
spain
[http://www.ibiblio.org/apollo/listings/Comanche055/PINBALL_G...](http://www.ibiblio.org/apollo/listings/Comanche055/PINBALL_GAME_BUTTONS_AND_LIGHTS.agc.html)

>Filename: PINBALL_GAME_BUTTONS_AND_LIGHTS.agc

Can someone explain what this is? I doubt they had an actual game of pinball
in their guidance computer.

~~~
egoebelbecker
It appears to be the code for the controls:

# THE KEYBOARD AND DISPLAY SYSTEM PROGRAM OPERATES UNDER EXECUTIVE

# CONTROL AND PROCESSES INFORMATION EXCHANGED BETWEEN THE AGC AND THE

# COMPUTER OPERATOR. THE INPUTS TO THE PROGRAM ARE FROM THE KEYBOARD,

# FROM INTERNAL PROGRAM, AND FROM THE UPLINK.

I think it's just someone with a sense of humor.

~~~
joezydeco
PINBALL (something flashy with buttons) was _a demo_. And that demo got us to
the moon:

 _" Apparently, nobody had yet arrived at any kind of software requirements
for the AGC's user interface when the desire arose within the Instrumentation
Laboratory to set up a demo guidance-computer unit with which to impress
visitors to the lab. Of course, this demo would have to do something, if it
was going to be at all impressive, and to do something it would need some
software. In short order, some of the coders threw together a demo program,
inventing and using the verb/noun user-interface concept, but without any idea
that the verb/noun concept would somehow survive into the flight software. As
time passed, and more and more people became familiar with the demo, nobody
got around to inventing an improvement for the user interface, so the coders
simply built it into the flight software without any specific requirements to
do so."_[1]

[1]
[http://www.ibiblio.org/apollo/ForDummies.html](http://www.ibiblio.org/apollo/ForDummies.html)

------
hyperliner
Wow. This is really impressive: assembler, real-time systems in space,
mission-critical equipment, software that protects lives, etc.

Maybe that is too much, causing those writing the next "date finding" app to
feel incompetent after reading this.

But at least we will know we are standing on shoulders of giants.

------
rejectedstone
Nice Documentation. I liked this line: 058113,000352: 11,3037 77656 UNIT
#PROBABLY UNNECESSARY.

~~~
morsch
Plus ca change...

[https://github.com/search?l=c&q=%22PROBABLY+UNNECESSARY%22&r...](https://github.com/search?l=c&q=%22PROBABLY+UNNECESSARY%22&ref=searchresults&type=Code)

------
mrweasel
It's of cause fun to have this code to look at, but is it really useful? I
don't mean it in a condescending way, but is this actually someone at, say
SpaceX, looks at and goes: "Oh so that's how they did that"?

~~~
RogerL
It's achingly beautiful to the pocket protector set (me!).

This source code, for example, contains the very first Kalman filter ever used
- Kalman was invited over to Moffett field to give talks about his paper,
which led to his theory was used in LM code. But I think everyone is very
aware of the state of the art at the time, and things have advanced a lot
since then. It is impressive to see them cramming that into such a limited
processor. But, 'whatever' as to that aspect of it. This is a historical
artifact of an amazing feat based on cutting edge research in
mathematics/control theory.

~~~
hcrisp
Wasn't it the PGNCS that had the Kalman filter? See my comment nearby which
confused it with AGC.

~~~
RogerL
It is my understanding that the AGC is the computer within the PGNCS.
Terminology varies, as the last link below from NASA notes.

So far as I can tell, the AGC maintained the state vectors for the KF. Ground
control would run batch mode least squares solutions, and pass it on to the
LM, where the updates to the state vector would be applied by hand. I freely
admit to not having worked through the code, but I believe the state vector
update computations occur here:
[http://www.ibiblio.org/apollo/listings/Comanche055/MEASUREME...](http://www.ibiblio.org/apollo/listings/Comanche055/MEASUREMENT_INCORPORATION.agc.html)

sources:
[http://www.ieeecss.org/CSM/library/2010/june10/11-Historical...](http://www.ieeecss.org/CSM/library/2010/june10/11-HistoricalPerspectives.pdf)

[http://en.wikipedia.org/wiki/Apollo_Guidance_Computer](http://en.wikipedia.org/wiki/Apollo_Guidance_Computer)

[http://en.wikipedia.org/wiki/Apollo_PGNCS](http://en.wikipedia.org/wiki/Apollo_PGNCS)
[http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/2009001...](http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20090016290.pdf)

~~~
hcrisp
Thanks, that helps. I've always wondered what the variables of the state
vector were -- position, velocity, etc. it appears from the link that it could
be a 6x6 of those two (position, velocity in x, y, and z), or a 9x9 when
including radar/landmark bias. Now I know!

------
rwinn
_Project Apollo features a near-full implementation of the control panels in
the Command Module and Lunar Module, and an increasingly accurate simulation
of the internal systems (e.g. electrical distribution, fuel cells). Also the
Virtual AGC software is supported, which allows you to run precisely the same
on-board guidance software as used by the real Apollo Guidance Computer_

[http://nassp.sourceforge.net/wiki/Main_Page](http://nassp.sourceforge.net/wiki/Main_Page)

------
hcrisp
Isn't it true that the AGC was initially designed to be the sole navigation
computer, but when the implementation did not meet the requirements for
accuracy (due to accelerometer and gyroscope drift), they switched to a
ground-based radar system? This meant the AGC became the back-up in case the
communications system failed. Does anyone know if the AGC was ever used to
make a mission-critical decision in the absence of the ground-based radar
system?

Edit: I think it was actually the PGNCS that was made back-up [1]. Sorry the
comment about Kalman filter had me confused. Apparently PGNCS was still used
for maintaining orientation, controlling rockets, and navigation during
planned outages.

1:
[http://en.wikipedia.org/wiki/Apollo_PGNCS](http://en.wikipedia.org/wiki/Apollo_PGNCS)

------
davegauer
For anyone interesting in learning more about this computer system, I highly
recommend _Digital Apollo: Human and Machine in Spaceflight_ by David A.
Mindell.

The hardware limitations! The incredibly low bug count! The memory hand-woven
by ladies in a factory! I was blown away by the capabilities of the Apollo
computer systems. The craft could have been practically unmanned.

Even more impressive, the computers could fly the craft while ALSO being
interrupted by and adjusting to human intervention at nearly every step of the
process. The pilots and the engineers practically battled over who would be in
control of the craft. Fascinating stuff!

------
kghose
If you are into such things, do take a look at the orbiter project
([http://orbit.medphys.ucl.ac.uk/](http://orbit.medphys.ucl.ac.uk/)) and the
NASSP add-on
([http://nassp.sourceforge.net/wiki/Main_Page](http://nassp.sourceforge.net/wiki/Main_Page)).
I spent many an after-school night flying to the moon by punching codes on a
keyboard. It was amazing.

edit: Here's a video
[https://www.youtube.com/watch?v=7VDV6Gdxakc](https://www.youtube.com/watch?v=7VDV6Gdxakc)

------
stuartk
In MAIN.agc there is a list of bugger words. Not that I know assembly in any
meaningful way, but I've never come across this term before.

On Googling, it seems to be something to do with a checksum value?

~~~
sternenseemann
yep, checksums

------
analog31
I don't know why, but I'm amused by the fact that there's no disclaimer about
warranties, express or implied.

------
ghaff
Also a lot of of good information in this document:
[http://www.ibiblio.org/apollo/hrst/archive/1029.pdf](http://www.ibiblio.org/apollo/hrst/archive/1029.pdf)

(Much of the Apollo Guidance Computer and software was developed by the MIT
Instrumentation Lab, the predecessor to Draper Lab.)

------
Oculus
The entire source code was actually woven by wire into memory for the Apollo
missions:
[https://www.youtube.com/watch?v=P12r8DKHsak](https://www.youtube.com/watch?v=P12r8DKHsak)

------
vrybas1
Story behind the code:

TALES FROM THE LUNAR MODULE GUIDANCE COMPUTER
[http://www.doneyles.com/LM/Tales.html](http://www.doneyles.com/LM/Tales.html)

------
MrBuddyCasino
previously:
[https://news.ycombinator.com/item?id=3888638](https://news.ycombinator.com/item?id=3888638)

related:

[https://news.ycombinator.com/item?id=3336584](https://news.ycombinator.com/item?id=3336584)

[https://news.ycombinator.com/item?id=6071825](https://news.ycombinator.com/item?id=6071825)

------
drinchev
I'm interested what computer languages do they use today for space vehicles?

I place my bet on static-type :D ( joke )

~~~
valevk
[https://news.ycombinator.com/item?id=4339999](https://news.ycombinator.com/item?id=4339999)

~~~
vans
WOW ! << Do not use direct or indirect recursion. Do not use dynamic memory
allocation after task initialization. >>

I think they should use COBOL, it's built in :)

~~~
Jtsummers
Those are standard restrictions for embedded real-time systems, especially if
the language itself doesn't offer guarantees on tail-call optimization (like
the ML family, Erlang and others do). You have to guarantee the behavior of
the program, and recursion (especially unbounded memory usage as in many C
implementations) can royally screw things up. You may still have infinite
loops because of an error in a for loop's terminating condition, but without
dynamic memory and exploding stack usage you'll at least have enough memory
left to deal with it when the watchdog timer kicks in.

------
Graham24
what are bugger codes?

[http://www.ibiblio.org/apollo/listings/Comanche055/MAIN.agc....](http://www.ibiblio.org/apollo/listings/Comanche055/MAIN.agc.html)

~~~
sternenseemann
bugger codes is the AGC term for checksums. (see "Playing with Colossus" on
this page: [http://www.ibiblio.org/apollo/](http://www.ibiblio.org/apollo/))

------
NietTim
What would it take to make a working simulator from this? Except a whole lot
of hardware of course

~~~
argaldo
Ron Burkey has a great simulator that uses the actual code ...
[http://ibiblio.org/apollo/index.html](http://ibiblio.org/apollo/index.html)
.... here you have an unfinished port of his simulator ( although functional )
for iOS devices ...
[https://github.com/argaldo/iAGC](https://github.com/argaldo/iAGC) ... which
all of you are greately encouraged to contribute patches .. ;-)

------
marclave
This is awesome!

------
restlessmedia
Tut, where are the supporting unit tests.

------
EnochSquareRoot
OMG. Where's the test coverage?

------
onion2k
I'm surprised to see that it was written in HTML.

;)

