[fpc-devel] Macro expansion in assembler code

Christo Crause christo.crause at gmail.com
Sat Jan 25 08:02:49 CET 2020

I noticed that macro's in assembler code is not expanded before the code is
parsed. Is there are technical reason this is not done, or is it merely a
historical artefact?

My question is prompted by the latest assembler code modifications to
accommodate avrtiny subarch in the AVR RTL, where the following type of
snippets are used in several places to accommodate the differences in
{$ifdef CPUAVR_16_REGS}
  in r16,63
{$else CPUAVR_16_REGS}
  in r0,63
{$endif CPUAVR_16_REGS}

It would seem neater to use a macro (defined by compiler in this case) to
indicate which register should be used as temp reg (similar to GCC):
{$ifdef CPUAVR_16_REGS}
  {$define AVR_TEMPREG := r16}
{$else CPUAVR_16_REGS}
  {$define AVR_TEMPREG := r0}
{$endif CPUAVR_16_REGS}

The assembler code can then more cleanly be written without further
conditional checks by using the macro:
  in AVR_TEMPREG, 63

Similarly reference to the zero register (r1 or r17) can benefit from being
defined through a macro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20200125/2d5eb6f8/attachment.html>

More information about the fpc-devel mailing list