|①⑨④⑧||Seventy years of the stored-program computer||②⓪①⑧|
The SSEM’s store consists of 1,024 binary digits (bits), divided into 32 words of 32 bits each. Unusually, SSEM binary numbers have the least significant digit first: so 1 means one, 01 means two, 001 means four, and so on. Even if you are quite familiar with binary notation, learning to read and write it back to front may take a little adjustment; if you are not familiar with it, you will find you cannot do much with the SSEM until you become so. Negative numbers are stored using two’s complement, as on most modern computers. Each word can therefore hold an integer between -2,147,483,648 and 2,147,483,647 inclusive; or it can hold an instruction. All 32 digits of the word are meaningful for an integer, but in the case of instructions most of them are not: depending on the instruction, only eight, or seven, or as few as three bits are actually used.
Two registers are accessible to the programmer: the accumulator, which is the main working register, and the control instruction register or CI, which tells the computer which word of the store contains the instruction it should execute. CI is incremented after each instruction, even if that instruction was a jump—meaning that if you want to jump to word 15, say, you have to ask for a jump to word 14. (This oddity, like the backwards binary numbers, survived as far as the Ferranti Mark 1.) The only meaningful values for CI are in the range from 0 to 31 inclusive, corresponding to the machine’s 32 words of storage: jumps to stated addresses lower than -1 or higher than 30 are invalid.
There are seven different instructions. The operand (if any) is always a store address, and occupies the leftmost five bits of the word; the instruction code itself is in bits 13 to 15. No assembler existed for the SSEM, but there is a mnemonic notation that can be used when drafting programs. It also appears on the JsSSEM disassembly listing.
|000||s to CI||jump to 1 + the number stored at s|
|100||Add s to CI||jump to the current address + 1 + the number stored at s|
|010||-s to c||load the negation of the number stored at s into the accumulator|
|110||c to s||store the number in the accumulator at s|
|001||Sub. s||subtract the number stored at s from the number in the accumulator, leaving the difference in the accumulator|
|101||Sub. s||exactly the same as 001|
|011||Test||skip next instruction if the number in the accumulator is negative|
Other arithmetic operations must be implemented using negation and subtraction. Note that the operand for a jump instruction—whether absolute or relative—is not the actual target of the jump but an address where that target is stored separately. (Every GO TO is an assigned GO TO.)
When you start JsSSEM, you are looking at the console tab. The top of the screen contains a graphical representation of the store and registers (only the low five bits of CI), a scrollable disassembly listing, and readouts for the registers and for the number of instructions executed. Further down, you will see 32 reddish buttons. Each of these is a switch that toggles a single bit in the word to which CI is currently pointing (initially word 0): the bottom left button controls bit 0, the button to the right of that controls bit 1, and so on. The five buttons that control the operand field in an instruction, and the three buttons that control the instruction field, are a brighter shade of red to help them stand out. The buttons marked Back to word 0, Back one, and Forward one let you move around the store toggling in the instructions and data you have prepared. (You should not be surprised if you find you often need pencil and paper, pseudocode, flowcharts, etc., to produce working SSEM programs, even if you would normally expect to write small programs without them: this is not a machine optimized for sketching out your ideas at the console.) The > cursor in the disassembly listing shows which word you are currently editing. When you are ready, click Back to word 0 to reset the CI register. You can then execute one instruction at a time by clicking Single instruction (useful for debugging) or run your program straight through by clicking Run program. The emulator’s speed is something like that of the real SSEM, but does not claim to be more than a vague approximation to it: it may run significantly slower, depending among other things on your device and browser, but it shouldn’t be faster. You can halt execution at any time by clicking Stop. The Reset machine button clears the store and registers.
The original SSEM had no external storage at all. JsSSEM does however provide a simulated paper tape reader and punch, to let you save and reload your programs using the base-32 encoding devised by Turing for the Manchester Mark 1. (The use of this system with the SSEM is something of an anachronism; but any alternative would be more of one.) To save the machine’s store to tape, click Paper tape and then Store->tape. You can then copy the tape’s contents and paste them somewhere for safekeeping. It is a good idea to save your program to tape before attempting to run it: that way you will have a clean copy, with the initial rather than the final values of your variables, in case you want to run it again (or to attempt to debug it). If you have a program on tape that you want to load, click Tape->store: the machine will be reset and the tape will be read in. The base-32 encoding is not hugely intuitive, but you may want to try learning it so that you can edit programs in paper tape format (or even write them that way from scratch—although the console is probably easier). Each word consists of seven digits, with the least significant digit first.
|0 /||1 E||2 @||3 A||4 :||5 S||6 I||7 U|
|8 ½||9 D||10 R||11 J||12 N||13 F||14 C||15 K|
|16 T||17 Z||18 L||19 W||20 H||21 Y||22 P||23 Q|
|24 O||25 B||26 G||27 "||28 M||29 X||30 V||31 £|
To make working with the base-32 encoding as comfortable as possible, the paper tape reader
(a) is not case-sensitive;
(b) ignores whitespace altogether;
(c) does not require all 32 words to be present: if your program is only ten words long, they will be loaded at addresses 0 to 9 and the others will be assumed to be equal to zero;
(d) accepts ; and ! as alternatives for ½ and £ respectively, in case the latter aren’t easily available on your keyboard.
Five sample programs are provided, ranging from elementary addition to a playable game with AI opponent. To run them, click on Sample programs and then on the title of the program you want to load: it will be mounted on the paper tape reader and you will be transferred to the paper tape tab, from where you can load the program (with Tape->store) and then run it from the console in the usual way.
The Addition and Multiplication programs show how to implement two of the arithmetic operations that the SSEM order code does not support directly; the first calculates the sum of store(5) and store(6), and the second calculates the product of store(29) and store(30). Division is not too hard, but is left as an exercise.
The Fibonacci sequence is the sequence 1, 1, 2, 3, 5, 8..., which occurs very widely in nature, art, and mathematics. The JsSSEM Fibonacci program finds the fortieth number in this sequence; to find the nth where 3 ≤ n ≤ 46, run the program with store(23) equal to n - 2.
The iterated Prisoner’s Dilemma is a game of strategy that is widely studied in game theory. You and an accomplice are being held by the police. If you confess and implicate each other, you will each be sentenced to two years in prison. If you both keep shtum, you will each be sentenced to one year on a lesser charge. But if one of you confesses and the other does not, then the one who confesses will be set free and the other will be sent down for three years. So, should you cooperate with your fellow detainee by remaining silent—or should you defect, by confessing? In the iterated version of the game, you are asked to make this decision again and again; and the aim of the game is to rack up the smallest number of years in prison that you can. To play the JsSSEM version against the computer, load the program and run it. The machine will halt with the accumulator showing your current score in years (initially zero); use the console to set store(2)—the word to which CI is pointing—equal to 0 if you want to cooperate or 1 if you want to defect. Then click Forward one followed by Run program again: the computer will make its own move, update the score, and halt with the accumulator showing your sentence ready for you to make your next move. You can keep playing until you get bored or until you have been sentenced to 2,147,483,647 years in prison. The computer plays according to Anatol Rapoport’s tournament-winning strategy, Tit for Tat.
Acknowledgement: JsSSEM uses Courier Prime Code, a font designed by Alan Dague-Greene that can be downloaded from here.
JsSSEM is provided ‘as is’ and any expressed or implied warranties are disclaimed. It is also provided for use free of charge with no advertising; if you find it interesting, and if you can afford it, you could consider supporting me on Patreon.
Please email me if you have any questions or if you find a bug.
Edmund Griffiths, 2018
Accumulator = CI =
Click on a program’s title to mount it on the paper tape reader. See notes for more information about each one.
Calculates 3 + 4 using negation and subtraction.
Calculates 1948 × -70.
Finds the fortieth number in the Fibonacci sequence.
Calls a reusable subroutine twice.
The iterated Prisoner’s Dilemma
Lets you play against the computer.