dasm-assembler / dasm

Macro assembler with support for several 8-bit microprocessors

Home Page:https://dasm-assembler.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable number of arguments for a macro

vitococl opened this issue · comments

From the manual:

Macros are instantiated by using the macro’s name (case-insensitive),
followed by an optional list of arguments. The body of the macro definition
can refer to arguments passed with the format “{#}”, where # is replaced by
the argument number. The first argument passed to a macro is therefore {1}.
{0} represents an exact substitution of the entire instantiation line.

If a macro is instantiated with more arguments than the used ones, there is no problem, but if you try to use an argument that it was not provided, DASM raises an exception.

It could be nice a way to check for the number of arguments, for instance {N}, allowing to write macros like this:

    macro addwords
        clc
        lda {1}
        adc {2}
        if {n} = 3
            sta {3}
            lda {1}+1
            adc {2}+1
            sta {3}+1
        else
            sta {1}
            lda {1}+1
            adc {2}+1
            sta {1}+1
        endif
    endm

    addwords $80,$82,$84 ; Result in $84
    addwords $80,$82     ; Result in $80

NOTE: currently, {N} returns the same as {0}, i.e. the placeholder is replaced by the full list of arguments. Bug?
NOTE2: if the condition expression is a comma separated list of argments, the IF is evaluated as "true". Bug?