Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

z80asm macros #814

Closed
maziac opened this issue Jun 14, 2018 · 6 comments
Closed

z80asm macros #814

maziac opened this issue Jun 14, 2018 · 6 comments
Assignees

Comments

@maziac
Copy link

maziac commented Jun 14, 2018

Hi,
sorry to put this here, but I haven't found any accurate place.

I'm trying to use macros with the z80asm Assembler but I can't find any documentation
about it.
How can I put macros in the assembler code (not in C but in pure assembler files) ?
What is the syntax?

@pauloscustodio
Copy link
Member

z80asm does not have macro support. The feature is planned, but not yet done.
The current solution is to run the z80asm source through m4 before assembly.

I will leave this topic open, to close when macros are implemented.

@pauloscustodio
Copy link
Member

There is a Perl script that you can run with perl -S asmpp.pl file.asm that implements the macro syntax used by the CP/M assembler Z80MR and calls z80asm:

name MACRO #param1,#param2
          LOCAL #local_label
#local_label:
          ....
          ENDM

          name 12, 34

@aralbrec
Copy link
Member

aralbrec commented Jun 14, 2018

M4 is integrated as a macro processing language.

Basic information:
https://en.wikipedia.org/wiki/M4_(computer_language)

Introduction:
http://mbreen.com/m4.html

m4 is a powerful language but it can also be annoying especially if you're a beginner. Doing basic macro substitution should be fairly easy though. The other option Paulo mentioned can also be done with a less dissimilar syntax.

@aralbrec
Copy link
Member

If a file ends in ".m4" then zcc will pass it through m4 before the next stage.

"foo.asm.m4" will pass through m4 to generate "foo.asm" (in the same directory!) which will then be passed to the assembler as usual.

"foo.c.m4" will pass through m4 to generate "foo.c" (in the same directory) which will then be passed to the c compiler as usual.

A couple of special filetypes ".inc.m4" and ".h.m4" will have m4 applied to result in ".inc" and ".h" respectively but processing stops there. These can then be used as includes into asm or c.

@developer500
Copy link

Even multi-line macros would be good (never mind macros with arguments) to re-use often used patterns.

@pauloscustodio
Copy link
Member

z80asm is now a macro assembler!

Implemented MACRO/ENDM, REPT/ENDR, REPTC/ENDR, REPTI/ENDR, EXITM, LOCAL, DEFL, #define, #undef

Documentation at https://github.com/z88dk/z88dk/wiki/Tool---z80asm---preprocessor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants