!lm12
!rm75
Using Macros and Nested Macros.....................Art Schumer

[ Art is a subscriber in Manvel, North Dakota; he is the programming side of S&H Software.  Art wrote the Universal Boot Initializer, The DOS Enhancer, and the AmperCat Utility. ]

The new S-C Macro Assembler is truly the best assembler around.  With the addition of Macros, easier programming is limited only by your imagination.  All you have to do is dream up some uses for Macros.  Are Macros and Nested Macros really worth using?  You bet!  One of my source files was 104 sectors long, but after going back through it and implementing macros, the file shortened to only 96 sectors; it was also easier to read.

As Bob pointed out in the manual, nested macros are allowed in this new version, but he frowned on their use.  I beg to differ with him, as I believe that nested macros can make your source files easier to read, as well as easier to write.  They may seem complex at first, but after setting them up they become very easy to use.

In my example program, I've defined a macro called GOTO.XY that will take two variables and use them to position the cursor.  Another defined macro called CLEAR.XY  is a singly nested macro that uses GOTO.XY to position the cursor, and then clears from there to the end of screen.  CLEAR.PRINT.XY positions the cursor (using GOTO.XY inside CLEAR.PRINT.XY), clears the rest of the screen, and prints a message.  It may sound confusing, but after examining the source listing and th macro definitions, it should be easy to understand how this all works.

In all the macros, the first variable is the horizontal cursor position and the second variable is the vertical cursor position.  CLEAR.PRINT.XY calls on a subroutine (JSR PRNT), which expects the message to follow the JSR instruction.  The message is terminated by a 00 byte, and execution proceeds at the instruction which follows the message in memory.

The PRNT subroutine came from a Call A.P.P.L.E. article by Andy Hertzfeld.

Have fun with your new S-C Macro Assembler!
