Course  
  Menu  
  Course  
 Description 
  Course  
  Outline  
 Assignments 
 & Doc Specs 
  Software  
  Summary  
  Class  
  Notes  
 Pseudocode 
  Modules  
  SIC/XE  
  Reference  
 Course  
 Supplement 
CNW Home
Loader Pseudocode.
   2 pass algorithm based on H, T, D, M, and E records

Pass 1: (build external symbol table)
BEGIN
  initialize Scnt to 0
  get Memaddr from operating system
  set CSaddr to Memaddr /*  control section address */
  WHILE not end of input
    BEGIN
      read input Record  /* header record */
      increment Scnt and set Sourceline[Scnt] to Record
      set CSname to csect name
      set CSlngth to csect length
      Xsearch EStable for CSname
      IF found THEN
        set error flag  /* duplicate external symbol */
      ELSE
        insert (CSname,CSaddr) into EStable
      ENDIF
      WHILE Record[0] <> 'E'
        BEGIN
          read next input Record
          increment Scnt and set Sourceline[Scnt] to Record
          IF Record[0] = 'D' THEN
            FOR EACH Symbol in Record
              BEGIN
                Xsearch EStable for Symbol
                IF found THEN
                  set error flag  /* duplicate external symbol */
                ELSE
                  insert (Symbol,CSaddr+symbol address) into EStable
                ENDIF
              END {for}
          ENDIF
        END {while}
      CSaddr <-- CSaddr + CSlngth /*  starting address for next csect */
    END (while}
  set Endcnt to Scnt
END {of Pass 1}
Pass 2: (install code and modify as called for)
BEGIN
  initialize Scnt to 0
  set CSaddr to MEMaddr
  set EXaddr to MEMaddr /*  default 1st executable instruction */
  WHILE Scnt <= Endcnt
    BEGIN
      increment Scnt and set Record to Sourceline[Scnt]
      set CSlngth to csect length /*  from Header record */
      WHILE Record[0] <> 'E'
        BEGIN
          increment Scnt and set Record to Sourceline[Scnt]
          IF Record[0] = 'T' THEN
            install object code from Record to Csaddr + specified address
          ELSE IF Record[0] = 'M' THEN
            BEGIN
              Xsearch EStable for Symbol in Record
              IF found THEN
                add/subtract Symbval from contents
                  of Csaddr + specified address
              ELSE
                set error flag  /* undefined external symbol */
              ENDIF
            END
          ENDIF
        END {while}
      IF Record /* an End record */ specifies an address THEN
        set EXaddr to Csaddr + specified address
      ENDIF
      CSaddr <-- CSaddr + CSlngth /*  starting address for next csect */
    END {while}
  jump to location given by EXaddr
END {of Pass 2}