Skip to content
Robert Kuhfß edited this page Oct 30, 2018 · 1 revision

SPASM macros were built to be fast, more than anything else. I generally preserve the functionality of other assemblers while keeping it simple. There are three types of macros, invoked by the preprocess keyword #define or in the case of argumented macros #macro. Refer to the #macro documentation for more info.

  • Dimensionless Macros (Boolean Defines)
  • Replacement Macros (Defines)
  • Argumented Replacement Macros

Dimensionless

Macros of this nature are not defined explicitly by the programmer, rather they are set to an arbitrary default. SPASM uses these as a quick Boolean Define for the #IFDEF preprocess.

#define on_emulator

#ifdef on_emulator
	push de
	pop ix
#else
	ld ixl,e
	ld ixh,d
#endif

Replacement

Replacement macros are the equivalent of a "named" copy and paste. They are not parsed until they are substituted, so they're ideal for making forward label references. Keep in mind that they can only make forward references to other defines as long as the define does not reference them in return.

#define value 56
#define other_value value+10

Defines like these can be used in the #IF preprocess:

#if other_value > value
	.dw other_value
#else
	.dw value
#endif

Argumented Replacement

The most complex of the macros, argumented replacement macros allows certain values of replacement macro to be changed before parsing. This allows the same macro to be used under multiple circumstances.

#macro my_modulo(base, mod)
 base - (base*(base/mod))
#endmacro
#define llo(val) (val & $FF)
 .db llo( my_modulo(10,3))
 .db my_modulo(10,3)

Macro Hacks

If a macro is parsed within an emit string (.db, .dw, .echo), the string contents of the macro are treated like a text replacement when they contain multiple comma-separated values

    #define test 10, 20
    .db test
Clone this wiki locally