GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CPU::Z80::Assembler::Macro(3) User Contributed Perl Documentation CPU::Z80::Assembler::Macro(3)

CPU::Z80::Assembler::Macro - Macro pre-processor for the Z80 assembler

  use CPU::Z80::Assembler::Macro;

  my $macro = CPU::Z80::Assembler::Macro->new(
                  name   => $name,
                  params => \@params_names,
                  locals => \%local_labels,
                  tokens => \@token_list);
  $macro->parse_body($input);
  $macro->expand_macro($input);

This module provides a macro pre-processor to parse macro definition statements, and expand macro calls in the token stream. Both the input and output streams are Iterator::Simple::Lookahead objects returning sequences of tokens.

The object created by new() describes one macro. It is used during the parse phase to define the macro object while reading the input token stream.

None.

Creates a new macro definition object, see Class::Struct.

Get/set the macro name.

Get/set the formal parameter names list.

Get/set the list of local macro labels, stored as a hash.

Get/set the list of tokens in the macro definition.

This method is called with the token input stream pointing at the first token after the macro parameter list, i.e. the '{' or ':' or "\n" character.

It parses the macro body, leaving the input stream after the last token of the macro definition ('endm' or closing '}'), with all the "\n" characters of the macro defintion pre-pended, and filling in locals() and tokens().

This method is called with the input stream pointing at the first token after the macro name in a macro call. It parses the macro arguments, if any and expands the macro call, inserting the expanded tokens in the input stream.

This method is called with the input stream pointing at the first token after the macro name in a macro call. It parses the macro arguments, leaves the input stream after the macro call, and returns an hash reference mapping formal argument names to list of tokens in the actual parameters.

The arguments are list of tokens separated by ','. An argument can be enclosed in braces '{' '}' to allow ',' to be passed - the braces are not part of the argument value.

Macros are created thus. This example creates an "instruction" called MAGIC that takes two parameters:

    MACRO MAGIC param1, param2 {
        LD param1, 0
        BIT param2, L
        label = 0x1234
        ... more real instructions go here.
    }

Within the macro, param1, param2 etc will be replaced with whatever parameters you pass to the macro. So, for example, this:

    MAGIC HL, 2

Is the same as:

    LD HL, 0
    BIT 2, L
    ...

Any labels that you define inside a macro are local to that macro. Actually they're not but they get renamed to _macro_NN_... so that they effectively *are* local.

There is an alternative syntax, for compatibility with other assemblers, with exactly the same effect.

    MACRO MAGIC param1, param2
        LD param1, 0
        BIT param2, L
        label = 0x1234
        ... more real instructions go here.
    ENDM

A ',' can be passed as part of a macro argument, by enclosing the arguments between {braces}.

    MACRO PAIR x {
        LD x
    }
    PAIR {A,B}

expands to:

    LD A,B

See CPU::Z80::Assembler.

CPU::Z80::Assembler Iterator::Simple::Lookahead

See CPU::Z80::Assembler.
2019-07-06 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.