• Keine Ergebnisse gefunden

MACRO CALLS

Im Dokument MANUAL AMOS (Seite 59-64)

The actual generation of the defined source code comes when you call the macro by its name within the text of your source program. The macro must have been defined prior to its first reference. Macros are onLy processed for definition during Phase 1 of the assembly process. Macro caLLs have the same format regardLess of whether the macro definition is muLtipLe or singLe

line format:

{Label:} name {reaL arguments} {;commments}

USER DEFINED MACROS Paqe 6-9

6.2.1 Name

Name represents the name given to the macro definition; this becomes the effective opcode by which your program caLLs the macro.

6.2.2 ReaL Arguments

Use reaL arquments when the definition of the macro has a dummy arqument List; they actuaLLy repLace the dummy arguments in the source code text of the macro definition. The real arguments repLace the dummy arguments on a one-for-one basis in exactLy the same order as the eLements of the dummy argument List. The first reaL argument in the caLL takes the pLace of p.ach occurrence of the first dummy arqument in the definition, and so on for aLL the arguments. If there are not enouqh reaL arguments qiven in the caLL to fiLL aLL required dummy arguments, the unfiLLed dummy arguments take on a nuLL vaLue and are effectiveLy replaced with nothing. If there are more arguments in the caLL then required to fiLL the dummy arguments in the definition, MACRO ignores the excess arguments.

6.2.2.1 ReaL Argument Format - NormaLly, the reaL arguments are separated by commas and the assembler expects this format. ALso, Leading and traiLinq bLanks are ignored when processing each reaL arqument in the macro caLL statement. Often you may want to incLude a comma or blank as part of the reaL argument without having it act as a deLimiter or be bypassed. Any argument that is encLosed in angLe brackets wiLL be passed onto the source code generation verbatim incLuding any blanks and commas.

The macro caLL:

XPURT ONE,TWO,THREE

has three reaL arguments whiLe the caLL:

XPURT <ONE,TWO,THREE>

has only one argument which incLudes the two commas. The caLL:

XPURT <ONE,TWO>,THREE

has two reaL arquments of which the first incLudes one comma.

USER DEFINED MACROS

The system macro TYPE ;s another good exampLe:

DEFINE TYPE MSG TTYI ASCII BYTE EVEN ENDM

/MSG/

o

Page 6-10

This macro is one of the AMOS monitor caLLs and is designed to type out the ASCII message which appears as the argument to the TYPE macro caLL. The BYTE 0 statement insures a nuLL terminator and the EVEN statement insures that the next instruction is again synchronized on a word boundary.

The ca L L :

TYPE HELLO

wiLL type out the message "HELLO" because aLL the automaticaLLy ignored before the argument is processed.

TYPE < HELLO >

Leading bLanks

The ca L l:

are

wiLL type out the message" HELLO" because the bLanks are included in the argument as a resuLt of the angLe brackets. SimiLarLy, the caLL:

TYPE HELLO, I AM A COMPUTER

wiLL type out the message "HELLO" because the comma wiLL terminate the argument and the rest of it wiLL be ignored. The caLL:

TYPE <HELLO, I AM A COMPUTER>

wiLL type out the message "HELLO, I AM A COMPUTER" because the comma is incLuded in the argument as a resuLt of the angLe brackets.

6.2.3 LabeL

The LabeL is optionaL and wiLL be assigned the address contained by the assembLy current Location counter. This wiLL normaLLy be the address of the first byte of code which is generated by the macro source Lines (assuming that the macro does actuaLLy generate code). If the macro does not generate code, then the LabeL wilL stiLL be defined but it wiLL represent the address of the next byte of code that is generated after the macro caLL.

USER DEFINED MACROS Paqe 6-11

6.2.4 Comments

As in other statements, comments are optionaL.

6.2.5 Nested Macro CaLLs

Macro caLLs may be nested to a depth of 16 LeveLs. A nested macro is defined as a macro caLL within the source statements generated by another macro caLL. Arguments may be passed to nested macros by naming the dummy arguments the same throughout the LeveLs. Arguments that contain bLanks or commas may be passed through successive Lev~Ls by encLosing them in one set of angLe brackets for each LeveL of nesting since one set of angLe brackets wiLL be removed from an argument with each nesting LeveL. For exampLe, to pass the argument A,B through three LeveLs of nested macro caLLs you wouLd enter the argument as «<A,B»> in the first LeveL macro caLL.

6.2.6 SampLe Macro CaLLs Consider this exampLe:

DEFINE TBLADD MOV ADD MOV ENDM

ARG1,ARG2,ARG3 ARG1,R1

ARG2,R1

R1,ARG1(ARG'3)

This macro ;s caLLed TBLADD and requires three reaL arguments.

foLLowing caLL in your proqram:

SAM: TBLADD SUMS,ENTRY,R5

The foLLowin~ source statements wouLd be generated:

SAM: MOV ADD MOV

SUMS,R1 ENTRY,R1 R1,SUMS(RS)

Assume the

It is evident from its usage that ARG3 must be a register. Assume that onLy two arguments were given in the caLL:

SAM: TBLADD SUMS,ENTRY

The foLLowing source statements wouLd be generated:

SAM: MOV ADD MOV

SUMS,R1 ENTRY,R1 R1 ,SUMS ()

USER DEFINED MACROS Page 6-12 Notice that the third instruction wouLd contain an error due to the missing register term which resuLted from the missing third argument. Sometimes a missing argument may be used to advantage by altering the generation of the source statements with the conditional assembLy statements. These statements (described in the next chapter) can detect the fact that the argument is missing and be used to seLectiveLy omit portions of code.

CHAPTER 7

CONDITIONAL ASSEMBLY DIRECTIVES

Conditional assembly directives allow you to selectively include or bypass certain lines or segments of source code based on variable parameters which are tested during assembly. This allows several different versions of the same program to be generated from one source file. Conditional assembly directives find their widest use within macro definitions where they are used to tailor the macro based on the real arguments used in the macro call.

NOTE: You may find the MACRO oarameterized assembly option especially useful when used with conditional assembly directives. The MACRO IV switch allows you to provide a value on the MACRO command line which can be examined by your source program. See Section 9.2.~ for information on this feature.

Im Dokument MANUAL AMOS (Seite 59-64)