Example of Table Processing

This example assumes we have an input file containing 80-byte records, each of which contains one positive integer in character format.

This program reads the file and loads the numbers into a table. The table has room for 50 numbers and the program will stop early if the table is full. After loading the table, we XDUMP it, just to be sure we loaded it correctly, and then we go through the table and print the contents, one number per line.


*********************************************************************
*
*   Register Usage
*
*   Register 1         Affected by XDECI
*   Register 3         Number from the input line or from the table
*   Register 5         Pointer into the table.
*   Register 14        Return address for ending the program
*   Register 15        Address of EXAMPLE itself
*
*********************************************************************
*
EXAMPLE  CSECT                         Entry point.
         USING EXAMPLE,15              Register 15 is our base register.
*
         LA    5,TABLE                 Point register 5 at TABLE. 
         XREAD BUFFER,80               Priming read.
*
* The 1st loop reads numbers from the file and puts them in the table.
*
TOPLOOP1 BC    B'0100',ENDLOOP1        If EOF, end the loop.
         C     5,=A(ENDTABLE)          If TABLE is full, we also
         BC    B'1010',ENDLOOP1        end the loop. 
         XDECI 3,BUFFER                Convert the number to binary.
         ST    3,0(0,5)                Store the number in the table.
         LA    5,4(0,5)                Advance the table pointer.
         XREAD BUFFER,80               Read the next record.
         B     TOPLOOP1                Go to the top of the loop.
ENDLOOP1 DS    0H                      End of this loop.     
*       
         ST    5,EOT                   Store the address of the 1st
*                                      unused table entry. 
*
* Just to check our work, we dump the table contents.
*
         XDUMP TABLE,ENDTABLE-TABLE    Dump the table contents.
*
         LA    5,TABLE                 Point register 5 at TABLE.
*
* The 2nd loop takes numbers from the table, puts them on the output
* line and prints the line.
*
TOPLOOP2 C     5,EOT                   Are we at the end?
         BC    B'1010',ENDLOOP2        If so, end the loop.
         L     3,0(0,5)                Load the number from the table
*                                      into register 5. 
         XDECO 3,NUM                   Put the number into OUTLINE.
         XPRNT OUTLINE,61              Print OUTLINE.
         LA    5,4(0,5)                Advance the table pointer.
         BC    B'1111',TOPLOOP2        Go to the top of this loop.
ENDLOOP2 DS    0H                      End of this loop.
*
         BR    14                      End the program.
         LTORG
*
* The storage for EXAMPLE starts here.
*
         LTORG                         Literal pool.
*
TABLE    DC    50F'-1'                 Table of numbers.
ENDTABLE DS    0H                      Marks end of TABLE.
EOT      DC    A(TABLE)                Address of 1st unused entry.
*
BUFFER   DS    80C                     Input line.
DSIGN    DC    C'$'
*
OUTLINE  DC    C' '                    Output line, single-spaced.
NUM      DS    12C                     The number being printed.
         DC    48C' '                  Filler.
*
         END   EXAMPLE                 End of the source code file.


Notes

We could use EQU to have a label ENTRYSIZ instead of hard-coding the value 4.

We could use extended mnemonics such as BM in place of BC B'0100'.

Notice that we have an LTORG. In the listing from the assembler, this is where we would find declarations for our literals.

Notice that the number of bytes for the XDUMP is supplied as TABLE-ENDTABLE. This is the difference of two implicit addresses, and the assembler will do the arithmetic for us.

The table is initialized to the value -1. In hexadecimal, this is X'FFFFFFFF', which is easy to spot in a dump.

Why do we have a dollar sign character at the end of BUFFER? Suppose by accident one of the lines in the file is all blanks. XDECI would search all the way through INLINE, skipping over blanks, and keep going, trying to find numeric characters. We want it to stop somewhere. We could improve this little program by testing whether, after XDECI, register 1 contains the address of DSIGN. If it does, we did not find a number, and we should just go on to the next line.

Notice that EOT is declared as A(TABLE). This is an example of an A-type address constant. "A" stands for "Address", and it takes up one fullword of space. The expression A(TABLE) has as its value the address of TABLE. We want to be sure EOT always has a value, and its value is always the first address after the last table entry in use. Before the table is loaded, that is the address of the first entry.