It’s easy to spot the thinking of long-forgotten legacy assembler programmers in the production code that runs on today’s systems. Working under the constraints of limited memory, these programmers developed techniques for making their code as small and as efficient as possible. While we’re not as memory constrained as these early programmers, you’ll still find their old techniques being practiced in today’s shops. When I code these old tidbits, I like to think of it as “tipping my cap” to programmers who came before me. Here are some examples:
Decrementing a register:
This is a simple way to subtract 1 from register five. Coding 0 for the second operand causes the flow of control to continue with the next instruction. We could just as easily have coded this:
So, why was the first technique originally preferred? BCTR is a register-to-register (RR) instruction and will run faster than the register-to-indexed storage (RX) version. Also the second version requires the assembler to build a fullword in memory. Today, we might not give a second thought to defining a field, but in 1964, every byte was precious.
Moving blanks to a field:
This technique has existed since the Ancient of Days.
Assume that field X is defined as below:
X DS CL80
The following code will move blanks to X :
MVI X,C’ ’
The MVI fills the first byte with a blank, and the MVC propagates blanks, one byte at a time, from left to right in field X. The length attribute L’X gets the assembler to plug in the correct length. Today we might code this without thinking:
BLANKS DC CL80’ ’
This technique requires an 80 byte field that the first method does not. But, what’s a few bytes among friends?
Loading a “small” number into a register:
This code will put 100 in register five:
What’s going on here? The assembler is looking for a base/displacement and perhaps an index register for creating the address that will be loaded into the register. Everything is explicitly coded and there are no parentheses. Explicit addresses look like this – D2(X2,B2) – that means the only thing the 100 can represent is a displacement. The base and index registers are assumed to be zero, and therefore don’t contribute to the effective address. If you use this technique, you are limited to a maximum value of 4095 – the maximum displacement that will fit in three hex digits. So why not just code this instead?
Well … that works fine, but again, our “modern” technique requires the assembler to build a fullword field that isn’t needed with the first method.
Do you have a favorite legacy technique I’ve missed? Let me hear from you.