The First Program

The first program was written by Torn Kilburn. It was a program to find the highest proper factor of any number a; this was done by trying every integer b from a-1 downward until one was found that divided exactly into a. The necessary divisions were done not by long division but by repeated subtraction of b (because the "Baby" had no hardware divider).

The original number used was quite small, but within a few days the team had built up to trying the program on 218. The program tested each number down from 262,143 (218-1) to 131,072 (217), which is the initial number's highest factor.

This meant that around 130,000 numbers were tested, which took about 2.1 million instructions and involved 3.5 million store accesses. The correct answer was obtained in a 52-minute run. The original program was encoded in only 17 instructions. . The revised version shown here is from the notebook of Geoff Tootill, Torn Kilburn's assistant. It includes two extra instructions to make it easier to run the program again with the same number. The original version overwrote the number being tested with the final answer, so it had to be keyed in again to repeat the test. Note that in the Baby and Mark I environments binary was written out with the least significant bit first — the opposite of modern binary notation.

The Baby instruction codes are as follows, given CI is the current control address, A is the Accumulator, and (S) is the contents of a store address:

Func.No. Binary code Instruction Description
0 000 CI = (S) Copy content of Store line to CI
1 100 CI = CI + [S] Add content of Store line to CI
2 010 A=-[S] Copy content of Store line, negated, to accumulator.
3 110 [S]=A Copy content of acc. to Store line.
4 001 A=A-[S] Subtract content of Store line from Accumulator
5 101 - Same as function number 4
6 011 If A=‹0,CI = CI + I Skip next instruction if content of Accumulator is negative
7 . 111 STOP Light 'Stop" neon and halt the machine

In his notebook, Geoff Tootill uses C (standing for "computer") to represent the Accumulator and CI for the control register (later called CI). Capital letters are used for the name of a location and lower-case letters for its contents. So a is the number for factorising, b is a trial factor and r is a remainder. The 19 line numbers of the program appear in the middle of the page. To the right of each is the binary code to be put into that particular line on the CRT store. The ones were keyed into the appropriate places on each line using the corresponding red buttons below the central monitor. They would appear on the monitor as small green dashes, replacing the dots representing zeroes normally contained in each position on the 32 x 32 grid. Only eight of the first 16 columns on the grid contained program information. The first five held a number for the program to work with, the next eight were not used and columns 13 to 15 held the three-digit instruction code. Geoff Tootill originally numbered the first block of columns from I to 5 before changing this to 0 to 4 by scribbling out the 5 and putting a 0 in front. As a result the columns of digits don't line up with the correct headings! The three small boxes written across the bottom give details of lines 20-27 which were used to store information apart from the program before and during its running. Lines 20 to 22 contained three numbers for the program to use when needed. Line 23 is where the negative of the number to be worked on would be input (-a), while line 24 contained the first factor for the computer to try (b1), which was one less than the initials number. With all these lines typed into the computer, the program could begin running. Lines 25 to 27 on the store would contain changing information.

On the left hand side of his notebook, Geoff Tootill has written what each line of code does and what its effect will be. So, the first instruction is to put the negative of whatever is in line 24 into the Accumulator (C). The binary code provides the computer with the number 24 and gives it the instruction (010) to copy what it finds in the line with that number, negate it and put it in the Accumulator.

The column headed C shows what should be in the Accumulator after each operation, while the columns headed 25 to 27 detail the changing contents of lines 25 to 27. The box in the bottom right hands corner gives the initial and final contents of those lines. The accumulator contents would still be positive after the first subtraction. So the program would continue to instruction 8, which is to add the contents of line 20 to the Control Register. The register is adding one to itself before it carries out each instruction, which gives it a line number to execute next. Adding the contents of line 20 reduces the number in the register to 5. So that, when it adds one to begin its next instruction, it will read line 6 again, taking the factor away from the remainder until the answer is negative.

When this condition is met, the program skips line 8 and jumps out of the loop to line 9 where the next sequence of instructions adds the last number subtracted and calculates the remainder. This is then negated and line 12 tests to see if the resulting number is negative. If the remainder was any positive number originally, it will now be negative. But if it was 0, it cannot be negative. When this happens, the program will not jump out of its second loop but continue on to line 13, which tells it to follow function number 7 and stop.

Otherwise, it proceeds to the final group of instructions, which reduce the factor by one and repeat the whole process until a factor is arrived at that can be subtracted an exact number of times and so leave the remainder as 0. When that happens and the computer stops, there will be a confirming 0 in line 25, where the current remainder (rn) is stored during the calculation. Try picking a (small!) number and working through Geoff Tootill's instructions yourself.

The original notebook A page from Geoff Tootill's notebook, showing the first program, with some explanation added underneath (not shown in the miniature alongside). A more detailed description of the Baby and its order code than that given here is given in the documentation associated with the The programmers' reference manual .

\