Examples have been given, in the earlier chapters of this guide, in which a programme has been so written that the computer obeys one set of instructions several times. This technique saves storage space and is of value whenever one small part of the calculation needs to be carried out more than once.
This chapter describes methods whereby this can still be done when either
Instances frequently occur in which the computer is required to carry out, several times, an action which is much the same at each repetition, but changes in some small detail each time it is performed. An elementary example is the addition of, say, 100 numbers stored in locations 100 to 199; after clearing the accumulator the functions to be performed are "add C(100)", "add C(101)", "add C(102)" ... "add C(199)". The action here is always "add", the change is an increase in the address of the addend.
Since instructions are stored in the computer in a numerical code, it is possible to cause a number to be added to an instruction, and thereby change or modify it, before it is obeyed. This could readily be done by using a function such as 24, specifying the location holding the instruction to be modified. Better still, in the addition problem considered above, would be function 22; for the addition of 2-38 to the content of a location is tantamount to an increase by 1 of the N in the second instruction therein.
But an automatic facility termed B-line Modification which is an improvement on either of the above is provided, and is as follows:
When a location (N1) is being used to hold a modifier, it is referred to as a B-line. This term is a legacy from one of the earlier Manchester University computers, in which numbers were represented by lines of dots on a cathode ray tube. The A-line contained the accumulator, and the B-line held the modification, if any, to be made to the next instruction.
There are restrictions on the combined use of B-line modification and transfer instructions, and function 77; these are stated in Appendix 3.
It is conventional to indicate B = 1 by placing a / in the B column rather than writing a 1.
It does not matter what use is made of the N1 digits in the first instruction.
If it is desired to have an instruction (F2 N2) modified by the content of location 173, we may write any of the following:
|
In the second instance, where C(173) is altered by function 22, the modification is by the new content
A situation is frequently reached, near the end of a calculation, in which the 5 right-hand digits of the accumulator correspond to a telecode character which must be punched on the output tape. The following instruction pair causes the computer to do this:
20 | 4 | / | 74 | 0 |
But observe that there must be no 1's in the accumulator in the F2 positions: for these would also be placed in location 4, and, when added to the the existing F2, would produce an instruction specifying some function other than 74.
Verify that, in Example 17, there may be 1's elsewhere in the accumulator (e.g. in the F1 positions, or in the 8 left-hand positions), without spoiling the effect.
If C(A) is -80 x 2-38 and C(238) is S, before the computer obeys
10 | 238 | / | 04 | 200 |
and C(238) = -80 x 2-38
This is employed below.
The following programme adds together 100 items, namely the contents of locations 100 to 199 inclusive, and exits with the sum in location 238. It is entered at the first instruction of location 240. (It is assumed that the sum is within capacity).
Address | Instructions | ||||||
F1 | N1 | B | F2 | N2 | |||
238 | Count location and total store | ||||||
239 | -100 | Count constant | |||||
240 | 26 | 238 | 30 | 239 | Set total to zero: replace -100 | ||
241 | 10 | 238 | / | 04 | 200 | Set count: add an item | |
242 | 12 | 238 | 41 | 241 | Count: test for end | ||
243 | Next part of programme. |
Note how the powerful "exchange" functions 10 and 12 are used. They enable the total-to-date and the count to be switched between location 238 and the accumulator. Without such functions it would be neccesary to allocate separate locations for the count and the total, and there would be more instructions in the loop.
Suppose that, during a lengthy calculation, it is neccesary to find square roots of several numbers. The need would then arise for the computer to carry out the functions of Example 12 several times, and that a considerable saving in storage requirements could be achieved by arranging that the same set of instructions is used each time, rather than having several sets, each to be used once.
This technique can be applied to any small section of programme which is designed to fulfil a standard requirement, and such sections of programme are termed subroutines. Several are available in the Elliott 803 Library of Programmes: these include, in addition to subroutines which form algebraic and trigonometrical functions of numbers, others which read numbers from the input tape or punch numbers on the output tape, carrying out the neccesary decimal-to-binary or binary-to-decimal conversion.
As far as is practicable, each subroutine is written to conform to the following standard:
00 | p | / | 40 | 1 |
The main programme and its subroutine(s) are placed in different parts of the store. Wherever it is required to employ the subroutine, an instruction pair of the following form is written in the main programme:
Address | Instructions | |||||
F1 | N1 | B | F2 | N2 | ||
z | 73 | p | 40 | p+1 | ||
z+1 | Next part of main programme. |
This causes the link, the "instruction" 00 z, to be placed in the spare location in the subroutine, and transfers to its entry point. When the subroutine has been obeyed, the exit instructions
00 | p | / | 40 | 1 |
To appreciate the value of this in programming, consider again the case in which several square roots must be found during a calculation. Provided steps are taken to see that the neccesary subroutine is in location p upwards, the instruction pair
73 | p |
|
This technique is employed even when a subroutine is used once during a calculation. For, by doing so, the need to have different versions of each subroutine is avoided, and so is the clerical effort of copying the instructions into the middle of a new programme.
Detailed examples are given in the next chapter.
Previous Chapter | Contents | Next Chapter |