Scheme B PERM & the Routine Changing Sequence    Date: 1952
     
    Written by R.A Brooker and A.Glennie

    from Programming the mark I: Early Programming Activity at the 
    University of Manchester (author: Martin Campbell-Kelly)

        Scheme A              Spring 1951   By A.Turing
        Scheme B              Spring 1952   Brooker and Glennie
        TELEINPUT (Scheme C)  Early 1953    Brooker

    Ferranti Mark I Programming Manual, second edition 
    Computer History Museum (https://computerhistory.org/)
    102724593-05-01-acc.pdf
    p83
    
    Floatcode - Bodleian Special Collection 
    MS. Eng. misc. b. 260-C.42.pdf
    p20, p22
     
    Explanation on how to use Scheme B can be found in Programming Manual 
    Second edition: p77-p116 (section Chapter 4. Programming (cont): Scheme B)
    
    Note by Roberto Sancho: on Programming Manual - Second edition - p83 and in 
    Bodleian Special Collection - MS. Eng. misc. b. 260-C.42.pdf - p20 the listing
    of R.C.S/B states word EE// at address SF. This is a magnetic instr that is
    used to load the directory to search the routine to be called. EE// stands
    for track 33. Nevertheless, on Programming Manual - Second edition - p112
    the B.PERM routine is listed again, and here the address FS contains
    word @E// (instead of EE//). This will load directory from Track 34, as
    stated in the doc. We keep this version.
    
     
    [Routine PERM & RCS ] 

    [Col : S  Track 97L]                [Col I U  Track 97R]       
                                               
    | //// | / | //// |         Stack   | GE// | / |      |                   
    | E/// | E | ///@ |                 | /A@/ | E |      |
    | //// | @ | //// |                 |      | @ |      |                  
    | @/// | A | ///: |                 |      | A |      |                  
    | //// | : | //// |                 |      | : |      |                  
    | :/// | S | ///# |                 |      | S |      |                  
    | //// | I | //// |                 |      | I |      |                  
    | #/// | U | ///T |                 |      | U |      |                  
    | //// | # | //// |                 |      | # |      |                  
    | T/// | D | $$$$ | const -1        |      | D |      |                  
    | //// | R | $$$$ |                 |      | R |      |                  
    | /E// | J | //// |                 |      | J |      |
    | //// | N | "S/L | Control number  |      | N |      |
    | /@// | F | @E// | Read 34 in S0   |      | F |      |
    | //// | C | ZSQG | [B7]=s+2,//     |      | C |      |
    | /:// | K | A:ZG | adjust B1       |      | K |      |
    | //// | T | S:/Q |___              |      | T |      |
    | /#// | Z | V$PO | constants       |      | Z |      |                  
    | //// | L | M$$$ |                 |      | L |      |                  
    | /T// | W | ZSQG | [B7]=s+2,//     |      | W |      |
    | //// | H | VSZZ | plants link     |      | H |      |
    | //E/ | Y | //QT | [B7]=2n,/V      |      | Y |      |
    | //// | P | @IEA | plants M        |      | P |      |
    | //@/ | Q | FS/: | call down dir   |      | Q |      |
    | //// | O | //UF | cue of new rout |      | O |      |
    | //:/ | B | /IEA | adds cue to list|      | B |      |
    | //// | G | LSZG | adjust [B1]     |      | G |      |
    | //#/ | " | VSEJ | restore acc     |      | " |      |
    | //// | M | A:ZG | adjust [B1]     |      | M |      |
    | //T/ | X | $SE: | call new routin |      | X |      |
    | //// | V | ///G | dummy stop      |      | V |      |
    | ///E | $ | VSEP | enters new rout |      | $ |      |
                  
    [End]
                         
    The m-th routine is called in as a sub-routine by the
    group of instructions:
    
           n   |  n  Q O     B7=*       (n, 2m = 2 characters)
           n+1 | G S / P     call RCS
           n+2 |  2m / V     const call routine m
           n+3 | ...         execution will continue here when subrourine
                             returns (with NS/P instr)

    B1 index Acts as stack pointer.

    A subroutine call needs 3 short lines
    On entry of subroutine, AM, AL and D can hold parameter for routine
    
    and as an ad-routine by 
    
           n   |  n  Q O        
           n+1 | Q S / P
           n+2 |  2m / V 
    
    If the programme involves the j-th level (master level
    j=0), then line pairs /I, @I, ... (2j) I are used by
    R.C.S/B. Line pair (2j+2) I is used as working space
    
    NS/P to return from sub-routine

    A directory track can hold up to 64 directory lines.
    dir is in track 34LR. 

    // / V -> references first routine in dir line //
    @/ / V -> references second routine in dir line @/
    :/ / V -> references third routine in dir line :/

    so the instructions    

         QS/P   
         ://V  -> will call thirst routine from dir 

    Each dir line needs 40 bits. Contains:

         tt // MGIN   

         Binary Digits 0..9 (tt, first 2 chars): 

         control transfer number. One less than the number of 
         line at witch the routine starts (the routine entry point)

         Binary Digits 20..39 (MGIN, last 4 chars) 

         Magnetic instr lo load routine   


S U M M A R Y
    
    Normal uses of pages                                       
    
    Column   Page   Use
    
    /        S0     Instructions
    E
    
    @        S1     Instructions
    A
    
    :        S2     PERM
    S
    
    I        S3     free (Reserve for PERM or)
    U               free 
    
    #        S4     free 
    D
    
    R        S5     free 
    J
    
    N        S6     free 
    F               free 
    
    C        S7     free 
    K               free 
    
Annotated program

   172  NS  "S/L  
   173  FS  @E//  
   174  CS  ZSQG  
   175  KS  A:ZG  
   176  TS  S:/Q  
   177  ZS  V$PO  
   178  LS  M$$$  
   179  WS  ZSQG  Entry from B.INPUT on G command: B7=B7+2: B7=ab.. = the return address when returning from subroutien
   180  HS  VSZZ  [B1 -@/I/ +/I]=B7 Save return addr in stack /I grows upwards
   181  YS  //QT  B7=[B7-1]=nn/V = the routine num to call in
   182  PS  @IEA  Save AM in [B1 -@/I/ +/I +4]
   183  QS  FS/:  Load directory from track 34 to S0
   184  OS  //UF  AM=cue from directory [// + B7]
   185  BS  /IEA  save cue in [B1 -@/I/ +/I +2] -> save in next entry of stack
   186  GS  LSZG  B1=B1+4 incr stack pointer
   187  "S  VSEJ  restore AM
   188  MS  A:ZG  Entry for SubRoutine return: B1=B1-2 adjust stack pointer
   189  XS  $SE:  Read new routine to S0/S1
   190  VS  ///G  Dummy stop /G
   191  $S  VSEP  transfer to cue control address (new routine entry point)
                  
