Joe Goes Small (< 4k)

Joe Developer had an astute comment about “Lots of Code on One Base Register” when he reminded me that lots of long programs have been written that use one base register, and without resorting to relative branches. By modularizing the program into sections of < 4k, you can write as much code as you like on one base register. There are some real benefits in his reminders. When designing programs, small is always a beautiful way to think. I thought it might be helpful to have an example program that illustrates the ideas. I’ve placed a copy of it here.
At 13k+, you have to admit it’s relatively long for a program that doesn’t do much of anything. I threw in a few odds and ends to illustrate some related ideas and concepts that might be of interest to someone learning assembler. Let me point out a few:

  1. The program is one source module organized into four control sections.
  2. Each control section can call the others. In this case, MAIN1 calls SUBR1 and SUBR2, and SUBR2 calls SUBR3.
  3. MAIN1 uses the CALL macro and passes parameters.
  4. SUBR2 invokes SUBR3 and passes parameters without using a CALL.
  5. SUBR1 illustrates passing parameters by content and by reference.
  6. MAIN1 passes a DCB which is used in SUBR1.
  7. Each routine is < 4k and uses standard linkage techniques (save and restore registers in save areas, parameter passing).
  8. Each routine uses a single base register.
  9. Each routine avoids the use of relative branching (although this would be fine, too).
  10. We could easily add more routines and make this arbitrarily large.
  11. Passing large amounts of data could be handled with different techniques.

There are other ways to write large programs and perhaps Joe had a different idea in mind, but I think this is close to what he was driving at.  And as Joe points out, 4k is not much of a constraint in most cases.  You can write a lot of assembler code in a 4k space – plenty of room for most well-designed modules.

Leave a Reply