📄 local.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- Local Symbols --><HTML><HEAD><TITLE>Local Symbols</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.4 Local Symbols</U></STRONG></P><P>Local symbols are symbols, which are only known within a macro body, but notoutside the macro. Symbols that are defined for the whole program, willsubsequently be called "global symbols" for better understanding.We are already familiar with a special case of local symbols: formal macroparameters. They appear in the macro definition only. Since they aresubstituted during macro expansion, we don't have further problems with them.But what happens with symbols that are defined in a macro body?</P><P><BR><STRONG>Example 1:</STRONG><BLOCKQUOTE>The following simple macro is intended to read a characterfrom the 8051 UART, and to return it in A:<PRE> RECEIVE MACROUARTIN: JNB RI,UARTIN MOV A,SBUF CLR RI ENDM</PRE>This will work only once! If the macro RECEIVE is calledmultiple times, the label UARTIN will be multiply defined.</BLOCKQUOTE></P><P>This can be solved by simply declaring the symbol UARTIN local.For this, the LOCAL statement has been introduced. After the keywordLOCAL, a list of local symbols can be specified, separated by commas.These symbols will only be valid inside the macro that contains the LOCALstatement. LOCAL statements may only be placed directly after the MACROor REPT statement, preceding the first body line. They may contain anynumber of local symbols. The macro body may be preceded by an arbitrarynumber of LOCAL statements.<BR>Local symbols must be valid symbols, unique within the macro, and differentfrom the formal parameters (if any). Keywords cannot be used as local symbolnames. If a local symbol has the same name as a global symbol, the localscope takes precedance during substitution.<BR>When a macro is expanded, its local symbols are always substituted: theformal parameters are replaced by the macro arguments, and the local symbolsthat have been declared in a LOCAL statement are replaced by unique, globalsymbol names, which the assembler generates during every expansion. Thesehave always the format ??xxxx, where xxxx is a unique symbol number.</P><P><BR><STRONG>Example 2:</STRONG><BLOCKQUOTE>After a redesign of our previous macro RECEIVE usinglocal symbols, it is looking as follows:<PRE> RECEIVE MACRO LOCAL UARTINUARTIN: JNB RI,UARTIN MOV A,SBUF CLR RI ENDM</PRE>Enhanced as shown above, the macro will work correctly,as often as desired. When RECEIVE is called for the firsttime, the local symbol UARTIN will be replaced by ??0000,<PRE>??0000: JNB RI,??0000 MOV A,SBUF CLR RI</PRE>when it is called for the second time, UARTIN will bereplaced by ??0001, and so on:<PRE>??0001: JNB RI,??0001 MOV A,SBUF CLR RI</PRE></BLOCKQUOTE></P><P>However, it is recommended not to define global symbols in the format ??xxxx,to avoid name conflicts with substituted local symbols from expanded macros.</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="repeat.htm"><IMG SRC="back.gif" ALT="[back]" BORDER=0 WIDTH=32 HEIGHT=32></A></TH> <TH><A HREF="operator.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 + -