Newsgroups: comp.sys.apple2.programmer Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@actrix.gen.nz (David Empson) Subject: Re: assembly macros Message-ID: Organization: Actrix Information Exchange References: <347c2p$l4c@schema.fiu.edu> Date: Sat, 3 Sep 1994 12:49:59 GMT Lines: 158 In article <347c2p$l4c@schema.fiu.edu>, Albert Chin-A-Young wrote: > I've used Merlin over the years and have never used the macro language > to any large extent. Supposedly, Orca/M provides a _much_ better > environment for working with macros and a much richer language. No argument there. Merlin's macros are very simple - all you can do is substitute parameters (and make loops out of things). ORCA has all sorts of weird and wonderful facilities, many of which I've never come to grips with. It is by far the most powerful macro facility of all assemblers I've used (possibly excluding MASM/TASM on the PC, but I haven't used them much so I'm not sure). Off the top of my head, and from a quick glance through the manual, I can spot the following features: - The label used on the macro line can be a macro parameter, and can be used in any way you like inside the macro, including placing it as a label at any position within the macro expansion. - Macro parameters are named, making the macro easier to understand. On the macro line, you can explicitly list parameters by name. e.g. here is a macro given in the ORCA/M manual, which prints two characters using the IIgs Text Tools. macro &lab putchar &c1,&c2 &lab lda &c1 pha ldx #$180C jsl $E10000 lda &c2 pha ldx #$180C jsl $E10000 mend Any of the following invocations opf the macro will print AB. putchar #'A',#'B' or putchar c2=#'B',c1=#'A' or char1 dc c'A' char2 dc c'B' putchar char1,char2 - You can have a macro parameter which is a list of values, and the macro can iterate through the parameters. - Sequence symbols, AIF and AGO directives, which allow very powerful conditional assembly operations (if a little cumbersome). You can construct loops, nested conditional structures, etc. (This can be used outside macros as well, but is particularly useful inside macros.) - Attributes of labels and macro parameters: subscript count, number of bytes defined on the line with the label, data type of a macro parameter or the instruction/directive on the line with a label. - Full expression support (Merlin is rather primitive by comparison) - String manipulation directives (AMID, ASEARCH), creating a symbolic parameter (which can also be created separately); these can be used just like macro parameters. Some of the more powerful things you can do with ORCA macros is dynamically adjust to handle any type of data passed as the argument to a macro. Take the "ph2" macro supplied with ORCA/M as an example. This macro pushes a two-byte value onto the stack. The operand can be an immediate value or expression, or an absolute or direct page variable reference. If an immediate value is specified, the macro generates a PEA instruction (push effective address, i.e. constant). If an explicit direct page reference is used (ph2 "{",.b ; Check for bracketed parameter &c amid &n1,l:&n1,1 ; Get the last character aif "&c"<>"}",.g ; Error if not close brace &n1 amid &n1,2,l:&n1-2 ; Remove the braces lda (&n1) ; Do the indirect reference pha ago .e ; Go to clean up code ; Not a bracketed parameter .b aif "&c"="<",.c ; Check for direct page reference ; Normal (absolute or [indirect]) reference lda &n1 pha ago .e ; Go to clean up code ; Direct page reference .c &n1 amid &n1,2,l:&n1-1 ; Remove the leading < character pei &n1 ago .e ; Immediate reference .d &n1 amid &n1,2,l:&n1-1 ; Remove the leading # character pea &n1 ago .f ; Clean up without touching A/M mode ; Clean up: restore A/M size if necessary .e aif s:longa=1,.f ; Do we need to restore 8-bit mode? sep #%00100000 .f mexit ; Get out now ; Error message .g mnote "Missing closing '}'",16 ; 16 is the error level mend Merlin can do quite a lot of this, but it does it by cheating. For example, Merlin ignores a # symbol on the argument to a PEA instruction, which is not strictly valid (you are pushing an address, not an immediate value). This means that Merlin can generate a PEA instruction for a PushWord macro argument starting with #. It does a LDA PHA sequence for everything else. Merlin can also test the M/X flag bit sizes. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand