reader_leader

Function reader_leader 

Source
pub fn reader_leader() -> Vec<Unsigned36Bit>
Expand description

Returns the standard reader leader.

The listing for this is given on page 5-26 of the User Handbook.

This program is superficially similar to Program VI (“A Binary Read-In Routine”) in Lincoln Lab Memorandum 6M-5780 (“Some Examples of TX-2 Programming”), but it is different in detail.

§Disassembly

Here’s a disassembly of the reader leader:

Loc  Symbolic assembly
00                   ** Used as a temporary for words read from tape
01                   ** unused?
02                   ** unused?

03   ¹RSX₅₄ 5        ** set X₅₄=-5
04  ³⁶JMP₅₄ 20       ** Call procedure to read first word into [0]
05 h ²RSX₅₃ 0        ** Set X₅₃ = L([0])  ([0] is saved in E)
06   ¹STE 11         ** Set R([11]) to the word we read from tape.

07  ³⁶JMP₅₄ 17       ** Call procedure at 17 (clear metabit, read word)
10 h  LDE   0        ** Load new word into E.

                     ** R([11]) is the end address of the current
                     ** block (this insruction is modified by the
                     ** instruction at 06).
11    STE₅₃ 34       ** Store new word at [X₅₃+end]
12 h ¹JNX₅₃ 7        ** Loop to 7 when X₅₃<0. Postincrement X₅₃.
13  ³⁶JMP₅₄ 20       ** Call procedure to read another word into [0]
14 h  JPX₅₆ 377760   ** if X₅₆ > 0, restart tape loading
15 h  JNX₅₆ 377760   ** if X₅₆ < 0, restart tape loading
16  ¹⁴JPQ 27         ** Call user program (the instruction at 25 may have
                     ** changed this address).

** Read-word procedure (entry point 1, clears meta bit)
17   ²MKZ₄.₁₂ 400011 ** Reset meta bit of [11]
** Read-word procedure (entry point 2, meta bit unaffected)
** On entry , X₅₄ is the return address.
20   ¹RSX₅₇ 3        ** Set R(X₅₇)=R(3) which is 5.
21 h  TSD 0          ** Read tape bits into [0].
22  ³⁶JPX₅₇ 21       ** Loop (to TSD) when X₅₇>0 (i.e. do whole word)
23   ¹AUX₅₆ 0        ** Add R[0] to X₅₆
24 h ²AUX₅₆ 0        ** Add L[0] to X₅₆
25   ¹STE 16         ** Set R[16] to E (which we loaded from [0]).
26  ¹⁵BPQ₅₄ 0        ** Branch to X₅₄ (no offset) - in other words, return.

Location 26 is the last word of the standard reader leader as
loaded by the boot code, but the assembler includes the
instructions after it in a special block loaded at location 27:

27 ¹IOS₅₂ 20000    ** Disconnect PETR, load report word into E.
                   ** This instruction is replaced by `JPQ AA` when
                   ** a start address is used with ☛☛PUNCH.

§Input Format

I believe the input format expected by the standard reader leader is:

header word: len,,end
The header is followed by (1-len) words of body
trailer word: sum,,next

All blocks start with len,,end where len is one plus the negated value of the actual length of the block in words (not including first and last). end is the address of the last word which should be written by this block.

Neither the header word nor the trailer word is written into the memory area identified by end.

The checksum calculation carried out in X₅₆ computes the unsigned 18-bit total of left and right halves of all words in the block (including the header and trailer words). This checksum must come out to 0, otherwise the reader leader will jump to 377760 to restart the loading process (which will re-load the bin, i.e. rewind the tape).

§First, Middle and Last Blocks

All blocks except the last block should be created and are used in the same way. The last block is different from the others simply because it has a different value of next.

The first block doesn’t have to do anything in particular. All blocks except the last should end with checksum,,3 in order to make the reader leader read the next block. The last block ends with checksum,,AA where AA is the execution start address of the user’s program.

§Minimal Example

I believe that the minimal tape content after the reader leader is a block containing a single word. This example shows such a block loaded at address 0o20000:

0,,20000
0
740000,,20000

Here the single word of the block (0) is loaded at 20000. The execution address is also 20000. The instruction at 20000 is 0. Since 0 is not a valid opcode, this program will fail. and the TX-2 will raise the illegal instruction (OCSAL) alarm.

The checksum value 0o740000 ensures that the total of all four halfwords is 0 (modulo 2^18).

§Start Address

Notice that the disassembly above shows that address 27 contains ¹IOS₅₂ 20000. This is taken from the listing on page 5-26 of the Users Handbook. That apparently contraditcs the commentary on page 6-23 of the same document, which states that the IOS instruction is at location 26. However, this difference is not material.

If we follow the advice given on page 6-23 for the last word of a block, we would set it to checksum,,26 meaning that the reader leader at locaiton 16 will jump to location 26. The instruction at 26 (which is ¹⁵BPQ₅₄ 0) will jump to the location in X₅₄. That will (I think) have been set to 27 by the previous execution of ¹⁵BPQ₅₄ 0. So jump to location 26 has the effect of jumping to location 27 but also sets X₅₄ (again) to 27. This seems indistinguishable from setting the R(last) to 27, because in that case we begin execution at 27 with X₅₄ set to 27.

When the execution address of the last block is not either 26 or 27, the user’s program will need to disconnect the paper tape reader if it doesn’t require it. This conclusion appears to contradict the guidance on page 6-23. The apparent contradition would be resolved if it were the case the M4 assembler adds a special first block containing a jump at location 28, when the ☛☛PUNCH directive includes a start address. This may in fact be the case shown in the diagram on page 6-23.