!pr0
!lm12
!rm75
So You Never Need Macros!..................Bob Sander-Cederlof

I have said it many times myself, "I don't need macros!"  But now that I have them, I seem to find more and more uses for them.  Not the traditional uses, to generate common sequences of opcodes.  I am using them to build tables of data, rather than typing in line after line of very similar stuff.

I have been working some more on the Prime Number Generator program.  You may remember the series:  first the articles in BYTE Magazine, then my faster version in an early Apple Assembly Line, then Charles Putney's version at double my speed.  Now Tony Brightwell has cut Charlie's time nearly in half.  (His program will probably appear next month.)  Anyway, I have done some more investigation.

One approach required a precomputed table of the squares of the odd numbers from 1 to 127.  An easy way to enter this table might be:

!lm+5
.DA 1*1,3*3,5*5,7*7,9*9
.DA 11*11,13*13,15*15,17*17
et cetera
!lm-5

I had type about that much when I said, "There has to be an easier way."  I made up the following macro definition:

!lm+5
       .MA SQ
:0     .EQ ]1
:1     .EQ ]1+2
:2     .EQ ]1+4
:3     .EQ ]1+6
:4     .EQ ]1+8
:5     .EQ ]1+10
:6     .EQ ]1+12
:7     .EQ ]1+14
       .DA :0*:0,:1*:1,:2*:2,:3*:3
       .DA :4*:4,:5*:5,:6*:6,:7*:7
       .DO ]2<8
       >SQ ]1+16,]2+1
       .FIN
       .EM
!lm-5

Then the single line of code

     2200         >SQ 1,1

generated all 64 squares for me.

How does it work?  Good question....  The eight .EQ lines create 8 private labels with the values of 8 consecutive odd numbers starting with whatever the first parameter from the call line happens to be.  Line 2200 has the first parameter "1", so the private labels will have values of 1, 3, 5, 7, 9, 11, 13, and 15 respectively.  The two .DA lines generate the squares of these 8 values.
!np
The next three lines are the tricky part.  If the second parameter has a value less than 8 then the line between .DO and .FIN is assembled.  It is a nested call on the SQ macro.  Only this time the first parameter is 16 greater than it was, and the second parameter is one greater.  After going through this nesting process 7 times, we will have generated 8 sets of 8 values each.  When the second parameter has worked its way up to 8, the nested calls will exit in turn, and the table is finished.

If you have the macro expansion listing option on during assembly, the expanded form takes 2 1/2 pages
