📄 params.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- Macro Parameters --><HTML><HEAD><TITLE>Macro Parameters</TITLE></HEAD><BODY BACKGROUND="spiral.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#990099" ALINK="#FF0000"><TABLE WIDTH="98%"><TR><TD WIDTH=60 VALIGN=BOTTOM NOWRAP><IMG SRC="transp.gif" ALT="" WIDTH=60 HEIGHT=20></TD><TD><!-- Ab hier Seitentext: --><BIG><BR><P><STRONG><U>III.11.2 Macro Parameters</U></STRONG></P><P>Callable macros may have parameters, to allow more flexible use.The names of the formal parameters are specified in the macro definitionbehind the keyword MACRO, separated by commas. All parameter names of amacro must be different, valid symbols. Keywords cannot be used asparameter names. Macros may have any number of parameters, as long as theyfit on one line. Parameter names are local symbols, which are known withinthe macro only. Outside the macro they have no meaning!</P><P><STRONG><PRE> <macro name> MACRO <parameter 1>, <parameter 2>, ... ,<parameter n> <body line 1> <body line 2> . . <body line m> ENDM</PRE></STRONG></P><P>When called, actual arguments can be passed to the macro. The argumentsmust be separated by commas. Valid macro arguments are</P><P><OL TYPE=1><LI>arbitrary sequences of printable characters, not containing blanks, tabs, commas, or semicolons<BR><BR></LI><LI>quoted strings (in single or double quotes)<BR><BR></LI><LI>single printable characters, preceded by '!' as an escape character <BR><BR></LI><LI>character sequences, enclosed in literal brackets < ... >, which may be arbitrary sequences of valid macro arguments (types 1. - 4.), blanks, commas and semicolons<BR><BR></LI><LI>arbitrary sequences of valid macro arguments (types 1. - 4.)<BR><BR></LI><LI>expressions preceded by a '%' character<BR><BR></LI></OL></P><P><STRONG>Note:</STRONG> The keywords MACRO, EQU, SET, CODE, DATA, IDATA, XDATA, BIT,and the ':' character cannot be passed as the first macro argument,because they always start a symbol definition!<BR>Therefore they must be enclosed in literal brackets < ... >.</P><P>During macro expansion, these actual arguments replace the symbols of thecorresponding formal parameters, wherever they are recognized in the macrobody. The first argument replaces the symbol of the first parameter, thesecond argument replaces the symbol of the second parameter, and so forth.This is called substitution.<BR>Without special assistance, the assembler will not recognize a parametersymbol if it</P><P><UL TYPE=DISC><LI>is part of another symbol</LI><LI>is contained in a quoted string</LI><LI>appears in commentary</LI></UL></P><P><BR><STRONG>Example 1:</STRONG><PRE> MY_SECOND MACRO CONSTANT, REGISTER MOV A,#CONSTANT ADD A,REGISTER ENDM MY_SECOND 42, R5</PRE><BLOCKQUOTE> After calling the macro MY_SECOND, the body lines</BLOCKQUOTE><PRE> MOV A,#42 ADD A,R5</PRE><BLOCKQUOTE> are inserted into the program, and assembled. The parameter names CONSTANT and REGISTER have been replaced by the macro arguments "42" and "R5".</BLOCKQUOTE></P><P>The number of arguments, passed to a macro, can be less (but not greater)than the number of its formal parameters. If an argument is omitted, thecorresponding formal parameter is replaced by an empty string.<BR>If other arguments than the last ones are to be omitted, they can berepresented by commas.</P><P><BR><STRONG>Example 2:</STRONG><BLOCKQUOTE> The macro OPTIONAL has eight formal parameters:</BLOCKQUOTE><PRE> OPTIONAL MACRO P1,P2,P3,P4,P5,P6,P7,P8 . . <macro body> . . ENDM</PRE><BLOCKQUOTE> If it is called as follows,</BLOCKQUOTE><PRE> OPTIONAL 1,2,,,5,6</PRE><BLOCKQUOTE> the formal parameters P1, P2, P5 and P6 are replaced by the arguments 1, 2, 5 and 6 during substitution. The parameters P3, P4, P7 and P8 are replaced by a zero length string.</BLOCKQUOTE></P><P>For more flexible macro design, there must be a possibility to recognizeempty macro arguments, and to branch the macro expansion accordingly.This can be performed with conditional assembly, using the IFB and IFNBmeta instructions.<BR>(See chapter <NOBR>"<A HREF="ifxxcon.htm">III.10.2 IFxx and ELSEIFxx Instructions</A>"</NOBR>.)</P></BIG><!-- Seitentext Ende --><P><BR><BR><CENTER><TABLE WIDTH="70%"><TR><TH><A HREF="contents.htm"><IMG SRC="home.gif" ALT="[contents]" BORDER=0 WIDTH=32 HEIGHT=32></A></TH> <TH><A HREF="macros.htm"><IMG SRC="up.gif" ALT="[up]" BORDER=0 WIDTH=32 HEIGHT=32></A></TH> <TH><A HREF="simple.htm"><IMG SRC="back.gif" ALT="[back]" BORDER=0 WIDTH=32 HEIGHT=32></A></TH> <TH><A HREF="repeat.htm"><IMG SRC="next.gif" ALT="[next]" BORDER=0 WIDTH=32 HEIGHT=32></A></TH></TR></TABLE></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -