Programming hints from Alan Turing (Mark I/II)

Discussion of development of software for any "obsolete" computer or video game system. See the WSdev wiki and ObscureDev wiki for more information on certain platforms.
Post Reply
User avatar
aa-dav
Posts: 220
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Programming hints from Alan Turing (Mark I/II)

Post by aa-dav »

Some time ago I found link to programming manual from 1951 year for one of the first british computers - Manchester/Ferranti Mark I/II and author was Alan Turing himself: http://curation.cs.manchester.ac.uk/com ... turing.pdf
There is interesting chapter "Programming Hints" on the page 55.
So, let's look at the good practices and best choices of programming craft of 1951 year... :)

Manchester/Ferranti Mark I/II (https://en.wikipedia.org/wiki/Manchester_Mark_1) had classic accumulator-memory architecture. RAM with registers were stored in Williams cathode ray tubes (CRTs). 20-bit instruction consisted of four 5-bit alphanumeric symbols. All letters/digits didn't fit in 32 variants of 5-bit values, so there were two "charset swap codes".
Charset was taken from telegraph, so here is base charset page:

Code: Select all

0  00000   /   8    00010   %   16   00001   T   24   00011   O
1  10000   E   9    10010   D   17   10001   Z   25   10011   B
2  01000   @   10   01010   R   18   01001   L   26   01011   G
3  11000   A   11   11010   J   19   11001   W   27   11011   "
4  00100   :   12   00110   N   20   00101   H   28   00111   M
5  10100   S   13   10110   F   21   10101   Y   29   10111   X
6  01100   I   14   01110   C   22   01101   P   30   01111   V
7  11100   U   15   11110   K   23   11101   Q   31   11111   ? 
(least significant bits were written from left-to-right!)
As you can note there is no system in letter code and it's position in alphabet. I think it's because 'bits' are just holes in punched tape and count of holes corresponds to fequency of letter in texts.
Image

Wll, let's look at the "hello, world" example (analogy) from Turing manual:

Code: Select all

// /CT/
E/ DSTI
@/ D//H
A/ R//P
:/ /C/S
S/ :CT/
I/ @CTI
U/ :C/S
%/ JS/P
D/ A/
R/ @/
Don't be afraid. First two-letter column is just line number (refer to charset table). / - is symbol with code 0, E - code 1, @ - code 2 and so on.
That is first column contains numbers from 0 to 10 in the codepage of this monumental machine.
Program itself resides in the second column. 20-bit numbers represented with four 5-bit letters. First two (10 bit) are memory cell numbers instruction works with. Last two - instruction codes merged with so called "B-tube code" which allows to do indexations. Brutal Manchester's engineers wrote programs in such way.

So, for now we are ready to go to page 55 of manual and read some programming hints from Alan Turing:
Manoevring space

It is seldom that one writes down a page of instructions for the first time withouthaving forgotten a few vital instructions. It is therefore considered desirable to aim,not at pages which are chock-full, but say at ones which are about five-eighths full.The extra space is best left between sequences of consecutive instructions, so that oncesequence may be extended without interfering with another.
Well... without assembler automatically relocating code and symbols it sounds good.
Do programming directly in teleprint code

It is never too soon to learn the meanings of the 64 functions [i.e., the opcodes]. The way to do so is to start programming in teleprint code straight away. Keep a list of themeanings always at hand, and refer to it as much as you wish: you will find that aftera week very few references are necessary. You will not yet know all the codes, but you will know a ‘working selection’. Likewise you will eventually get to know the teleprint equivalents (p. 3), but this is likely to be slower, chiefly because it is less essential to know them. ... Later it will be desirable to know the teleprint equivalents of the single characters by heart, but it is never necessary to know the equivalents for pairs of characters.
Sounds extreme, but honest.
Counting procedure

One of the commonest operations is a sequence of instructions to be repeated a givennumber of times. ...
Here Turing explains general algorithm for loops for this machine.
Discrimination by control transfer

When two cases have to be given quite different treatment, involving different se-quences of instructions, it is natural to choose the relevant sequences by a test in-struction (i.e. conditional transfer/T,/H,/M, or/O). ...
Turing explains how to do "case of" integer number using indexing registers of machine (jump table).
Omission of counting

If the operation to be repeated contains rather few instructions e.g. three, and is crucial for the speed of the whole process it may be best to omit the instructionsconcerned with counting and to repeat the instructions concerned with the process inquestion the requisite number of times.
Loops unrolling!
Alternative entry

It is often necessary to have a number of routines differing in certain minor particulars. One would like to use essentially the same instructions for all of them. The most convenient method seems to be to use one assembly of instructions, with various points of entry. The cues of these routines will then differ only in their first ten digits.
This trick is still usefull in assembler.
Changing sign in the accumulator

The instruction DSTJ has the effect A′={1−A±} which for most purposes is as good as A′={−A±} which can only be achieved in two instructions, or more if 80 digits are required.
I suppose it can be done if next calculations can be changed to include "-1" for correction.
Clearing the accumulator

The beginner is liable either to leave things in the accumulator to get mixed upwith the next calculation or else to put in accumulator clearing instructions which could easily have been avoided. In fact it is very seldom necessary to give a specialinstruction for clearing the accumulator, if the points below are held in mind. ...
Here Turing notes instructions automatically clearing accumulator and some general calculation facts, like "If an expression of form a+bc is required and the accumulator is not clear the term 'a' should be put into the accumulator first.".
Electronic space economy measures

We have explained that the economising of instructions in order to reduce the spaceoccupied in the magnetic store is seldom worth while. There are however occasionswhen it is worth while to economise them to save space in the electronic store. ...
Electronic RAM worked faster than magnetic drum memory, so here Turing recommends some methods of it's economy. For example - placing useful data in address part of addressless instruction.

Well... I would say many of this techniques still are useful in modern retroprogramming. :)
coto
Posts: 102
Joined: Wed Mar 06, 2019 6:00 pm
Location: Chile

Re: Programming hints from Alan Turing (Mark I/II)

Post by coto »

aa-dav wrote: Mon Jun 01, 2020 9:45 pm Some time ago I found link to programming manual from 1951 year for one of the first british computers - Manchester/Ferranti Mark I/II and author was Alan Turing himself: http://curation.cs.manchester.ac.uk/com ... turing.pdf
There is interesting chapter "Programming Hints" on the page 55.
So, let's look at the good practices and best choices of programming craft of 1951 year... :)

Manchester/Ferranti Mark I/II (https://en.wikipedia.org/wiki/Manchester_Mark_1) had classic accumulator-memory architecture. RAM with registers were stored in Williams cathode ray tubes (CRTs). 20-bit instruction consisted of four 5-bit alphanumeric symbols. All letters/digits didn't fit in 32 variants of 5-bit values, so there were two "charset swap codes".
Charset was taken from telegraph, so here is base charset page:

Code: Select all

0  00000   /   8    00010   %   16   00001   T   24   00011   O
1  10000   E   9    10010   D   17   10001   Z   25   10011   B
2  01000   @   10   01010   R   18   01001   L   26   01011   G
3  11000   A   11   11010   J   19   11001   W   27   11011   "
4  00100   :   12   00110   N   20   00101   H   28   00111   M
5  10100   S   13   10110   F   21   10101   Y   29   10111   X
6  01100   I   14   01110   C   22   01101   P   30   01111   V
7  11100   U   15   11110   K   23   11101   Q   31   11111   ? 
(least significant bits were written from left-to-right!)
As you can note there is no system in letter code and it's position in alphabet. I think it's because 'bits' are just holes in punched tape and count of holes corresponds to fequency of letter in texts.
Image

Wll, let's look at the "hello, world" example (analogy) from Turing manual:

Code: Select all

// /CT/
E/ DSTI
@/ D//H
A/ R//P
:/ /C/S
S/ :CT/
I/ @CTI
U/ :C/S
%/ JS/P
D/ A/
R/ @/
Don't be afraid. First two-letter column is just line number (refer to charset table). / - is symbol with code 0, E - code 1, @ - code 2 and so on.
That is first column contains numbers from 0 to 10 in the codepage of this monumental machine.
Program itself resides in the second column. 20-bit numbers represented with four 5-bit letters. First two (10 bit) are memory cell numbers instruction works with. Last two - instruction codes merged with so called "B-tube code" which allows to do indexations. Brutal Manchester's engineers wrote programs in such way.

So, for now we are ready to go to page 55 of manual and read some programming hints from Alan Turing:
Manoevring space

It is seldom that one writes down a page of instructions for the first time withouthaving forgotten a few vital instructions. It is therefore considered desirable to aim,not at pages which are chock-full, but say at ones which are about five-eighths full.The extra space is best left between sequences of consecutive instructions, so that oncesequence may be extended without interfering with another.
Well... without assembler automatically relocating code and symbols it sounds good.
Do programming directly in teleprint code

It is never too soon to learn the meanings of the 64 functions [i.e., the opcodes]. The way to do so is to start programming in teleprint code straight away. Keep a list of themeanings always at hand, and refer to it as much as you wish: you will find that aftera week very few references are necessary. You will not yet know all the codes, but you will know a ‘working selection’. Likewise you will eventually get to know the teleprint equivalents (p. 3), but this is likely to be slower, chiefly because it is less essential to know them. ... Later it will be desirable to know the teleprint equivalents of the single characters by heart, but it is never necessary to know the equivalents for pairs of characters.
Sounds extreme, but honest.
Counting procedure

One of the commonest operations is a sequence of instructions to be repeated a givennumber of times. ...
Here Turing explains general algorithm for loops for this machine.
Discrimination by control transfer

When two cases have to be given quite different treatment, involving different se-quences of instructions, it is natural to choose the relevant sequences by a test in-struction (i.e. conditional transfer/T,/H,/M, or/O). ...
Turing explains how to do "case of" integer number using indexing registers of machine (jump table).
Omission of counting

If the operation to be repeated contains rather few instructions e.g. three, and is crucial for the speed of the whole process it may be best to omit the instructionsconcerned with counting and to repeat the instructions concerned with the process inquestion the requisite number of times.
Loops unrolling!
Alternative entry

It is often necessary to have a number of routines differing in certain minor particulars. One would like to use essentially the same instructions for all of them. The most convenient method seems to be to use one assembly of instructions, with various points of entry. The cues of these routines will then differ only in their first ten digits.
This trick is still usefull in assembler.
Changing sign in the accumulator

The instruction DSTJ has the effect A′={1−A±} which for most purposes is as good as A′={−A±} which can only be achieved in two instructions, or more if 80 digits are required.
I suppose it can be done if next calculations can be changed to include "-1" for correction.
Clearing the accumulator

The beginner is liable either to leave things in the accumulator to get mixed upwith the next calculation or else to put in accumulator clearing instructions which could easily have been avoided. In fact it is very seldom necessary to give a specialinstruction for clearing the accumulator, if the points below are held in mind. ...
Here Turing notes instructions automatically clearing accumulator and some general calculation facts, like "If an expression of form a+bc is required and the accumulator is not clear the term 'a' should be put into the accumulator first.".
Electronic space economy measures

We have explained that the economising of instructions in order to reduce the spaceoccupied in the magnetic store is seldom worth while. There are however occasionswhen it is worth while to economise them to save space in the electronic store. ...
Electronic RAM worked faster than magnetic drum memory, so here Turing recommends some methods of it's economy. For example - placing useful data in address part of addressless instruction.

Well... I would say many of this techniques still are useful in modern retroprogramming. :)
Interesting read..!!

Reading that guy reminds me of Mel Kaye. It's very structural thinking. But both guys think about machines from a hardware view point, or planar thinking (as solving a 2d algebra exercise, given the scope is to generate behaviour out of varying degrees of inputs). I'd strongly recommend to watch John Carmack conferences because his thoughts resemble a more linear algebra thought. If you want to understand 3D or project things onto different planes better
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Programming hints from Alan Turing (Mark I/II)

Post by rainwarrior »

Interesting!
User avatar
aa-dav
Posts: 220
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Programming hints from Alan Turing (Mark I/II)

Post by aa-dav »

coto wrote: Tue Jun 02, 2020 12:09 pm ... Reading that guy reminds me of Mel Kaye. It's very structural thinking. ...
Even selective reading this manual was hard. :) First of all Alan Turing was mathematician and manual starts with math language and full of it. But it's not just symbols, but math formalism also. Modern (for last 30-40 years at least) way to write about programming is way more about tech than math.
Alan Turing do really describe Mark I/II processor as 'state machine' concepts, and do it like this:
...
It is usual to describe it in terms of ‘obeying an instruction’. The original state Σ of the machine determines an instruction I(Σ), and this instruction gets ‘obeyed’, i.e. the final state Φ(Σ) or Σ′ is determined by I(Σ) and Σ. This is simply a way of saying that Φ(Σ) can be written in the form Ψ(I(Σ),Σ). We may describe Ψ(I,Σ) as ‘the result of obeying the instruction I when the machine is in state Σ’. The step from writing Φ(Σ) to writing Ψ(I(Σ),Σ) is not by itself a very helpful one, for any function Φ could be expressed in this form (e.g. even if I(Σ) always had the same value for every Σ)
...
Wow! But this is simply way of saying 'machine executes instructions and changes state strictly according to them in order of them'. That's all. :)
But look at all this strict wording. It is pioneering of programming manual writing of it's time. :) And I love it.
Also I would say there was not enough experience how to introduce in the instruction set. Very quick and discouraging effort to fed you with cryptic relatively long program. I think this text was read ten times per one understanding. :)))
Anyway it's really cool to read such... ancient artifact. :)
coto
Posts: 102
Joined: Wed Mar 06, 2019 6:00 pm
Location: Chile

Re: Programming hints from Alan Turing (Mark I/II)

Post by coto »

Heh if there existed people able to talk to birds or to play around with wireless electricity makes me wonder why can't we yet even understand the human brain. I get the feeling most inventions were just an accidental out of pre-discovery

I was amazed people creating video games, or smart programs that would interact between the user and the computer. In fact creating a video game is like applying the earlier logic but exponential to the degree of realism you can achieve through maths. That's like a real life simulation inside a computer! To this day I really admire pioneering engineers because they can use maths not only to translate something that happens inside a program or transistors but also to "project" AI, sound, graphics or whatever idea you may have.

As a step up from Alan Turing, out of relay states people invented SDK, game programs, spatial maths AI, etc.

I think there's even a bigger picture how matter affect atoms as these traverses the universe, and somewhat John Carmack went to research that.
There's a group of pioneering in 3D graphics and I think that guy is one of them.
Post Reply