!lm12
!rm75
Recursive Macro Example............................Lee Meador

[ Lee is a subscriber from Arlington, Texas.  He wrote the original code for the .TF directive and REPLACE command in the S-C Assemblers. ]

Here is short example of a useful macro that uses a recursive definition.  By recursive I mean that the definition calls itself.

Most large computers have a shift instruction which can shift any number of bits; the 6502 shifts only shift one bit at a time.  The LSR macro shown here accepts a shift count as the first parameter, and generates one LSR opcode for each bit shift you want.

The second parameter is optional.  If there is no second parameter, the A-register will be shifted.  If you specify a variable for the second parameter, that memory location will be shifted.  Both cases are shown in the example below.

How does it work?  The definiton says to test the first parameter; if it is greater than zero, generate the LSR with the optional second parameter as the address field, and call on the LSR macro with the first parameter decremented by one.  If the first parameter is zero (and it eventually will be), no code is generated.  Read the listing carefully, noting the indentation, and you should be able to follow it.
