Home + About me + E-mail me

Programming the Sinclair Cambridge Programmable

Can you do anything useful in an 18-byte program?

the machine

It used to have a name but it wore off; the key legends are fading too.

Key functions

key base function upshift function downshift function prog base function prog downshift function prog num function prog symbol comment
./EE/- ./EE/-     downshift   ./EE/- A decimal point / enter exponent / negate exponent
up/down up and down shift             once for up, twice for down
C/CE clear/clear entry step           once for CE, twice for C; step in learn mode
7 7 sin arcsin sin arcsin 7 7  
8 8 cos arccos cos arccos 8 8  
9 9 tan arctan tan arctan 9 9  
RUN RUN learn           run the stored prog; enter learn mode
4 4 lnx ex lnx ex 4 4  
5 5 rcl MEx rcl MEx 5 5 recall from mem; exchange with mem
6 6 () R>D () R>D 6 6 parens; radians to deg
/ /           G 1/x memo to auto constant function
1 1 sqrt go if neg sqrt go if neg 1 1 2-dig step # after go if neg
2 2 sto goto sto goto 2 2 store; 2-dig step # after goto
3 3 ChN D>R # D>R 3 3 show all 8 digits of mantissa; escape to number; deg to radians
x x           . x2 memo to auto constant function
0 0   +/- stop +/- 0 0  
= =           -  
+ +           E 2x memo to auto constant function
- -           F -x memo to auto constant function

The trick used to minimise keystrokes is to treat program and direct entry differently. In direct entry number keys enter numbers and other functions are accessed by single (up) or double (down) presses of the shift key. On the assumption that programs are more functions than data, in program mode the number keys do the upper function with no shift, the lower on one shift, and numbers only after a specific numeric shift. This is rather confusing to use, but is a typical Sinclair trick to get something out of almost nothing. Or possibly almost something out of next to nothing.

Only the 16 keys with an entry in the "prog symbol" column can be in a program. The symbol is the 7-segment symbol used to indicate the contents of a program step. The symbol is the numeric value, or the symbol shown in blue below to the right of the key.

There are 36 steps available, 00 to 35 (18 bytes total).

Functions shown in "prog base function" can be used as a single step. Functions shown in "prog downshift function" use 2 steps, a downshift (shows as A) followed by the key from the table.

Numbers can be placed in the program after a # step (shows as 3). Numbers are terminated by anything that cannot be part of a number, basically the four arithmetic operators and =. It's a lot more efficient to put in a number by a recall from memory.

The ./EE/- key succesively enters a decimal point, then starts an exponent, then makes the exponent negative.

The legends below the arithmetic keys hint at useful functions -x, 2x, 1/x and x2. These are not true operators, just an indication of what, with no pending operations, the autoconstant function will do if that key is pressed, then the = key.

Here is a silly program that just counts the memory up by one each time the RUN key is pressed:

00 5  rcl
01 E  +
02 3  #
03 1  1
04 -  =
05 2  sto
06 0  stop
07 A  downshift
09 2  goto
09 0  0
10 0  0

Model of the Sinclair Cambridge Programmable

A quick Javascript model:

keyboard

Press the keys to operate. Power key does a complete reset. The display does not do exactly what the real one does, and it's far too accurate. To catch infinite loops, maximum program execution is set to 5000 steps. (To play, load the example factorial program using the link below, enter an integer 1..69 and press RUN.)

Control

De-bug on (100 steps max)
De-bug off

Example programs

Factorial: Load. Details

Counter: Load. The simple counter example above.

I've done almost no testing. There are sure to be numerous bugs! The code is here.

EE FG CCE power 7 8 9 RUN 4 5 6 DIV 1 2 3 MUL 0 EQU ADD MIN

Sinclair maths

This calculator, like previous Sinclair Scientifics, has appalling trig functions. For example, [4] [5] [D>R] [sin] gives 0.7069515 instead of the correct 0.7071068, that's a 0.02% error on an 8-digit calculator. But there is worse. Observe this sequence of calculations:

#radianssine calculated true value (hp49g+)
10.10.099823 0.0998334
20.100090.099823 0.0999230
30.10010.0999224 0.0999329
40.100190.0999224 0.1000225
50.10020.1000218 0.1000324
60.100290.1000218 0.1001220
70.10030.1001212 0.1001319
80.063200.0631504 0.0631579
90.063290.0631504 0.0632478
100.063300.0632502 0.0632577

It appears to use only the first four places of decimals and to ignore any input after that. So, about the same as ordinary log tables.

It also does not even cover the full -pi/2 to pi/2 range that it claims. Here is the behaviour around the positive limit:

#radianssine calculated true value (hp49g+)
111.570.9998869 0.9999997
121.5700001E 0.9998854 0.9999997
131.570001E 0.9998854 0.9999997
141.57001E 0.9998854 0.9999997
151.57002E 0.9998854 0.9999997
161.57009E 0.9998854 0.9999998
171.5701E 0.9998853 0.9999998
181.5705E 0.9998831 1.0000000
191.5707E 0.999882 1.0000000
201.5707963E 0.9998814 1.0000000
211.5708E 0.9998814 1.0000000
221.571E 0.9998803 1.0000000
231.58E 0.999829 0.9999576

Firstly the error indicator comes on too early, pi/2 is 1.5707963, yet it indicates error for angles greater than 1.57. Secondly 1.5700xxx is the angle for the peak value of the function, at 89.95° instead of 90°. Thirdly the peak value is a little short of 1. Note also in this sequence that although the results are generally insensitive to decimal places beyond four in the argument, the transitions are not where the 4th decimal digit changes.

I wonder what it does to calculate sines? Even the simple power series for sine truncated after the fourth term:

sin(x) ~= x - x3/6 + x5/120 - x7/5040

gives better results than this over -pi/2 to pi/2. And that simplifies to just five multiplies and three adds.

Some other functions:

#function and argumentresult calculated true value (hp49g+)
24sqrt(2)1.414213 1.4142136
25ln(2)0.693172 0.6931472
26tan(D>R(45))0.9995621 1.0000000
271/90.1111111 0.1111111
28e1022024.952 22026.466
29eln(2.02)2.0198033 2.0200000
30arctan(1)0.7854105 0.7853982

Today we can buy a scientific calculator that does much more than this one, with 15-digit accuracy and solar powered, for the price of two pints of beer. Back in 1977, any scientific that didn't cost a week's wages was remarkable. I suppose it was about 30 GBP when I bought it. The cost of two pints then would have been about 1 GBP. In 1975 I paid 125 GBP for an HP-25, which was then 5% of my gross salary or 88% of one month's net pay.

More calculator stuff.


nib 2006-03-22..2015-04-11

Home + About me + E-mail me

Valid HTML 4.01!