Macro declaration and usage


MACRO nom,param1,param2,param3,...

A macro is a way of extending the language by defining a block of instructions, delimited by MACRO / MEND (or ENDM) and which can be inserted later in the code by simply using the name of the macro. Macros can take parameters, which makes it possible to use conditions in the code. At each call, the macro code is inserted and the declared parameters are substituted. Then the code is interpreted in the classical way. Example of a long distance indirect writing:

macro LDIXREG register,dep
if {dep}<-128 || {dep}>127
   push bc,ix
   ld bc,{dep}
   add ix,bc
   ld (ix+0),{register}
   pop ix,bc
   ld (ix+{dep}),{register}

To make it easier for the assembler to find its way around, the convention for passing parameters is similar to that of Winape, with the use of parameters between curly brackets.

Macro call

Be careful! RASM can't know if you want to declare a label when you make a mistake in writing the name of a macro without parameter. To overcome this, you can add a dummy parameter "(void)" which will trigger an error if the name of the macro is not known. Moreover, if you want to force the use of this syntax, it is possible to launch RASM with the -void option. Using a macro without parameters will cause an error. This is the recommended way!

macro withoutparam
withoutparam (void) ; secured call

Macro call with dynamic values

It is possible to evaluate the parameters before sending them to the macro

macro test myarg
   defb {myarg}

; équivalent à defb 1, 2
repeat 2
   test repeat_counter

; équivalent à defb 1,1
repeat 2
   test {eval}repeat_counter ; the first call in the loop will evaluate the counter and set the value before passing the argument

Decomposition of 16-bit registers

In a macro, it is possible to use .low and .high to use the high or low byte of a 16-bit register. Example:

macro add16,R1,R2
ld a,{R1].low
add {R2}.low
ld {R1}.low,a
ld a,{R1].high
adc {R2}.high
ld {R1}.high,a

Sauf mention contraire, le contenu de cette page est protégé par la licence Creative Commons Attribution-ShareAlike 3.0 License