| CSCI 567 | Assembler Coding Guidelines |
The first assignment in Applied Systems Programming usually produces a spectrum of coding techniques. Nearly everyone develops an individual style. The following unordered list contains suggestions for better coding.
Comments are not optional. A block comment should describe each section of code, and statement comments should be on most lines. In particular, comments should be useful rather than simply helping to use up the world's supply of toner.
Register usage should follow a pattern. Registers 0, 1, and 13-15 already have defined uses, so if they are needed elsewhere it must be for very brief sections of code (0 and 1 are good scratch registers but are often changed across macro invocations). Of the remaining 2-12, a good practice is to use the higher numbered registers for longer duration applications. Thus R12 for a DSECT shared among routines, R11 for a program base, etc. This leaves the lower-numbered registers for scratch, or for modification by machine instructions (like TRT).
Also on the topic of register usage, never use R13 as a program base. It should be used solely as a save area pointer. The use of R13 as both a save area pointer and a program base is a bad programming habit.
Every program should be written so that it is reentrant. This is not difficult to do but it requires some planning. On the other hand, making reentrant a program which was not originally written that way is very difficult and usually requires nearly a complete rewrite.
Making a program reentrant requires the use of GETMAIN/FREEMAIN or STORAGE macros to acquire scratch areas which can be modified. Such requests for virtual storage should be made for subpool zero unless there is a specific reason for using a non-zero subpool (such as when many small requests are made and all are to be freed, so it is easiest to free an entire subpool). A portion of subpool zero is allocated at program start (why?) and so a block has already been set aside; starting a new subpool will require setting aside another complete block.
The addressing mode (AMODE) and residency mode (RMODE) of each control section (CSECT) should be specified on the appropriate assembler statements and included next to the corresponding CSECT statements in the input stream.
If you are writing a single-CSECT program, make sure the CSECT name and the program name are the same; this will avoid potential problems later.
There is almost never a reason to use START in a "production" program. Specifying an initial location counter value has the potential to make a program nearly impossible to debug; consider the difficulties in tracing a program loaded at F000 but whose initial location counter is, say, E000. Always use CSECT to begin a program (or START 0 if you must).
Avoid Private Code (code outside a CSECT which cannot be accessed). All executables as well as EQUs should be placed within a CSECT.
The BSM instruction is intended to return control only in situations where BASSM was used to give control. Also, BSM 0,R14 is preferred over BSM R0,R14 (why?).
Use PRINT GEN for executable code so that we can see what has been generated by macros. PRINT NOGEN is acceptable for macro-generated DSECTs at the end of an assembly.