annotate doc/manual/x445.html @ 274:3010e24bb9c5 2.5

Fix crashing on bad expressions on pass 2
author lost
date Mon, 31 Aug 2009 08:30:13 +0000
parents d5392bb5da3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
d5392bb5da3c Added generated files
lost
parents:
diff changeset
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
d5392bb5da3c Added generated files
lost
parents:
diff changeset
2 <HTML
d5392bb5da3c Added generated files
lost
parents:
diff changeset
3 ><HEAD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
4 ><TITLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
5 >Macros</TITLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
6 ><META
d5392bb5da3c Added generated files
lost
parents:
diff changeset
7 NAME="GENERATOR"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
d5392bb5da3c Added generated files
lost
parents:
diff changeset
9 REL="HOME"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
10 TITLE="LW Tool Chain"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
11 HREF="index.html"><LINK
d5392bb5da3c Added generated files
lost
parents:
diff changeset
12 REL="UP"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
13 TITLE="LWASM"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
14 HREF="c43.html"><LINK
d5392bb5da3c Added generated files
lost
parents:
diff changeset
15 REL="PREVIOUS"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
16 TITLE="Assembler Directives"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
17 HREF="x173.html"><LINK
d5392bb5da3c Added generated files
lost
parents:
diff changeset
18 REL="NEXT"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
19 TITLE="Object Files and Sections"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
20 HREF="x467.html"></HEAD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
21 ><BODY
d5392bb5da3c Added generated files
lost
parents:
diff changeset
22 CLASS="SECTION"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
23 BGCOLOR="#FFFFFF"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
24 TEXT="#000000"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
25 LINK="#0000FF"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
26 VLINK="#840084"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
27 ALINK="#0000FF"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
28 ><DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
29 CLASS="NAVHEADER"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
30 ><TABLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
31 SUMMARY="Header navigation table"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
32 WIDTH="100%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
33 BORDER="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
34 CELLPADDING="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
35 CELLSPACING="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
36 ><TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
37 ><TH
d5392bb5da3c Added generated files
lost
parents:
diff changeset
38 COLSPAN="3"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
39 ALIGN="center"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
40 >LW Tool Chain</TH
d5392bb5da3c Added generated files
lost
parents:
diff changeset
41 ></TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
42 ><TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
43 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
44 WIDTH="10%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
45 ALIGN="left"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
46 VALIGN="bottom"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
47 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
48 HREF="x173.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
49 ACCESSKEY="P"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
50 >Prev</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
51 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
52 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
53 WIDTH="80%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
54 ALIGN="center"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
55 VALIGN="bottom"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
56 >Chapter 3. LWASM</TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
57 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
58 WIDTH="10%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
59 ALIGN="right"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
60 VALIGN="bottom"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
61 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
62 HREF="x467.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
63 ACCESSKEY="N"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
64 >Next</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
65 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
66 ></TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
67 ></TABLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
68 ><HR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
69 ALIGN="LEFT"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
70 WIDTH="100%"></DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
71 ><DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
72 CLASS="SECTION"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
73 ><H1
d5392bb5da3c Added generated files
lost
parents:
diff changeset
74 CLASS="SECTION"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
75 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
76 NAME="AEN445"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
77 >3.7. Macros</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
78 ></H1
d5392bb5da3c Added generated files
lost
parents:
diff changeset
79 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
80 >LWASM is a macro assembler. A macro is simply a name that stands in for a
d5392bb5da3c Added generated files
lost
parents:
diff changeset
81 series of instructions. Once a macro is defined, it is used like any other
d5392bb5da3c Added generated files
lost
parents:
diff changeset
82 assembler directive. Defining a macro can be considered equivalent to adding
d5392bb5da3c Added generated files
lost
parents:
diff changeset
83 additional assembler directives.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
84 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
85 >Macros my accept parameters. These parameters are referenced within
d5392bb5da3c Added generated files
lost
parents:
diff changeset
86 a macro by the a backslash ("\") followed by a digit 1 through 9 for the first
d5392bb5da3c Added generated files
lost
parents:
diff changeset
87 through ninth parameters. They may also be referenced by enclosing the
d5392bb5da3c Added generated files
lost
parents:
diff changeset
88 decimal parameter number in braces ("{num}"). These parameter references
d5392bb5da3c Added generated files
lost
parents:
diff changeset
89 are replaced with the verbatim text of the parameter passed to the macro. A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
90 reference to a non-existent parameter will be replaced by an empty string.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
91 Macro parameters are expanded everywhere on each source line. That means
d5392bb5da3c Added generated files
lost
parents:
diff changeset
92 the parameter to a macro could be used as a symbol or it could even appear
d5392bb5da3c Added generated files
lost
parents:
diff changeset
93 in a comment or could cause an entire source line to be commented out
d5392bb5da3c Added generated files
lost
parents:
diff changeset
94 when the macro is expanded.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
95 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
96 >Parameters passed to a macro are separated by commas and the parameter list
d5392bb5da3c Added generated files
lost
parents:
diff changeset
97 is terminated by any whitespace. This means that neither a comma nor whitespace
d5392bb5da3c Added generated files
lost
parents:
diff changeset
98 may be included in a macro parameter.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
99 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
100 >Macro expansion is done recursively. That is, within a macro, macros are
d5392bb5da3c Added generated files
lost
parents:
diff changeset
101 expanded. This can lead to infinite loops in macro expansion. If the assembler
d5392bb5da3c Added generated files
lost
parents:
diff changeset
102 hangs for a long time while assembling a file that uses macros, this may be
d5392bb5da3c Added generated files
lost
parents:
diff changeset
103 the reason.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
104 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
105 >Each macro expansion receives its own local symbol context which is not
d5392bb5da3c Added generated files
lost
parents:
diff changeset
106 inherited by any macros called by it nor is it inherited from the context
d5392bb5da3c Added generated files
lost
parents:
diff changeset
107 the macro was instantiated in. That means it is possible to use local symbols
d5392bb5da3c Added generated files
lost
parents:
diff changeset
108 within macros without having them collide with symbols in other macros or
d5392bb5da3c Added generated files
lost
parents:
diff changeset
109 outside the macro itself. However, this also means that using a local symbol
d5392bb5da3c Added generated files
lost
parents:
diff changeset
110 as a parameter to a macro, while legal, will not do what it would seem to do
d5392bb5da3c Added generated files
lost
parents:
diff changeset
111 as it will result in looking up the local symbol in the macro's symbol context
d5392bb5da3c Added generated files
lost
parents:
diff changeset
112 rather than the enclosing context where it came from, likely yielding either
d5392bb5da3c Added generated files
lost
parents:
diff changeset
113 an undefined symbol error or bizarre assembly results.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
114 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
115 >Note that there is no way to define a macro as local to a symbol context. All
d5392bb5da3c Added generated files
lost
parents:
diff changeset
116 macros are part of the global macro namespace. However, macros have a separate
d5392bb5da3c Added generated files
lost
parents:
diff changeset
117 namespace from symbols so it is possible to have a symbol with the same name
d5392bb5da3c Added generated files
lost
parents:
diff changeset
118 as a macro.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
119 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
120 >Macros are defined only during the first pass. Macro expansion also
d5392bb5da3c Added generated files
lost
parents:
diff changeset
121 only occurs during the first pass. On the second pass, the macro
d5392bb5da3c Added generated files
lost
parents:
diff changeset
122 definition is simply ignored. Macros must be defined before they are used.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
123 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
124 >The following directives are used when defining macros.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
125 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
126 ></P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
127 ><DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
128 CLASS="VARIABLELIST"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
129 ><DL
d5392bb5da3c Added generated files
lost
parents:
diff changeset
130 ><DT
d5392bb5da3c Added generated files
lost
parents:
diff changeset
131 ><CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
132 CLASS="PARAMETER"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
133 >macroname</CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
134 > MACRO</DT
d5392bb5da3c Added generated files
lost
parents:
diff changeset
135 ><DD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
136 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
137 >This directive is used to being the definition of a macro called
d5392bb5da3c Added generated files
lost
parents:
diff changeset
138 <CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
139 CLASS="PARAMETER"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
140 >macroname</CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
141 >. If <CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
142 CLASS="PARAMETER"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
143 >macroname</CODE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
144 > already
d5392bb5da3c Added generated files
lost
parents:
diff changeset
145 exists, it is considered an error. Attempting to define a macro within a
d5392bb5da3c Added generated files
lost
parents:
diff changeset
146 macro is undefined. It may work and it may not so the behaviour should not
d5392bb5da3c Added generated files
lost
parents:
diff changeset
147 be relied upon.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
148 ></DD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
149 ><DT
d5392bb5da3c Added generated files
lost
parents:
diff changeset
150 >ENDM</DT
d5392bb5da3c Added generated files
lost
parents:
diff changeset
151 ><DD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
152 ><P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
153 >This directive indicates the end of the macro currently being defined. It
d5392bb5da3c Added generated files
lost
parents:
diff changeset
154 causes the assembler to resume interpreting source lines as normal.</P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
155 ></DD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
156 ></DL
d5392bb5da3c Added generated files
lost
parents:
diff changeset
157 ></DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
158 ></DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
159 ><DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
160 CLASS="NAVFOOTER"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
161 ><HR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
162 ALIGN="LEFT"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
163 WIDTH="100%"><TABLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
164 SUMMARY="Footer navigation table"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
165 WIDTH="100%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
166 BORDER="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
167 CELLPADDING="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
168 CELLSPACING="0"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
169 ><TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
170 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
171 WIDTH="33%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
172 ALIGN="left"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
173 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
174 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
175 HREF="x173.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
176 ACCESSKEY="P"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
177 >Prev</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
178 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
179 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
180 WIDTH="34%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
181 ALIGN="center"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
182 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
183 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
184 HREF="index.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
185 ACCESSKEY="H"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
186 >Home</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
187 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
188 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
189 WIDTH="33%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
190 ALIGN="right"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
191 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
192 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
193 HREF="x467.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
194 ACCESSKEY="N"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
195 >Next</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
196 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
197 ></TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
198 ><TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
199 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
200 WIDTH="33%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
201 ALIGN="left"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
202 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
203 >Assembler Directives</TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
204 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
205 WIDTH="34%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
206 ALIGN="center"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
207 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
208 ><A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
209 HREF="c43.html"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
210 ACCESSKEY="U"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
211 >Up</A
d5392bb5da3c Added generated files
lost
parents:
diff changeset
212 ></TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
213 ><TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
214 WIDTH="33%"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
215 ALIGN="right"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
216 VALIGN="top"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
217 >Object Files and Sections</TD
d5392bb5da3c Added generated files
lost
parents:
diff changeset
218 ></TR
d5392bb5da3c Added generated files
lost
parents:
diff changeset
219 ></TABLE
d5392bb5da3c Added generated files
lost
parents:
diff changeset
220 ></DIV
d5392bb5da3c Added generated files
lost
parents:
diff changeset
221 ></BODY
d5392bb5da3c Added generated files
lost
parents:
diff changeset
222 ></HTML
d5392bb5da3c Added generated files
lost
parents:
diff changeset
223 >