comparison docs/manual/x585.html @ 489:52af0aa54fe5

Update html and pdf documentation in preparation for release
author William Astle <lost@l-w.ca>
date Fri, 03 May 2019 20:06:17 -0600
parents
children
comparison
equal deleted inserted replaced
488:94bbdb2890b7 489:52af0aa54fe5
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Structures</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
9 REL="HOME"
10 TITLE="LW Tool Chain"
11 HREF="index.html"><LINK
12 REL="UP"
13 TITLE="LWASM"
14 HREF="c62.html"><LINK
15 REL="PREVIOUS"
16 TITLE="Macros"
17 HREF="x562.html"><LINK
18 REL="NEXT"
19 TITLE="Object Files and Sections"
20 HREF="x606.html"></HEAD
21 ><BODY
22 CLASS="SECTION"
23 BGCOLOR="#FFFFFF"
24 TEXT="#000000"
25 LINK="#0000FF"
26 VLINK="#840084"
27 ALINK="#0000FF"
28 ><DIV
29 CLASS="NAVHEADER"
30 ><TABLE
31 SUMMARY="Header navigation table"
32 WIDTH="100%"
33 BORDER="0"
34 CELLPADDING="0"
35 CELLSPACING="0"
36 ><TR
37 ><TH
38 COLSPAN="3"
39 ALIGN="center"
40 >LW Tool Chain</TH
41 ></TR
42 ><TR
43 ><TD
44 WIDTH="10%"
45 ALIGN="left"
46 VALIGN="bottom"
47 ><A
48 HREF="x562.html"
49 ACCESSKEY="P"
50 >Prev</A
51 ></TD
52 ><TD
53 WIDTH="80%"
54 ALIGN="center"
55 VALIGN="bottom"
56 >Chapter 3. LWASM</TD
57 ><TD
58 WIDTH="10%"
59 ALIGN="right"
60 VALIGN="bottom"
61 ><A
62 HREF="x606.html"
63 ACCESSKEY="N"
64 >Next</A
65 ></TD
66 ></TR
67 ></TABLE
68 ><HR
69 ALIGN="LEFT"
70 WIDTH="100%"></DIV
71 ><DIV
72 CLASS="SECTION"
73 ><H1
74 CLASS="SECTION"
75 ><A
76 NAME="AEN585"
77 >3.8. Structures</A
78 ></H1
79 ><P
80 >&#13;Structures are used to group related data in a fixed structure. A structure
81 consists a number of fields, defined in sequential order and which take up
82 specified size. The assembler does not enforce any means of access within a
83 structure; it assumes that whatever you are doing, you intended to do.
84 There are two pseudo ops that are used for defining structures.&#13;</P
85 ><P
86 ></P
87 ><DIV
88 CLASS="VARIABLELIST"
89 ><DL
90 ><DT
91 ><CODE
92 CLASS="PARAMETER"
93 >structname</CODE
94 > STRUCT</DT
95 ><DD
96 ><P
97 >&#13;This directive is used to begin the definition of a structure with name
98 <CODE
99 CLASS="PARAMETER"
100 >structname</CODE
101 >. Subsequent statements all form part of
102 the structure definition until the end of the structure is declared.&#13;</P
103 ></DD
104 ><DT
105 >ENDSTRUCT, ENDS</DT
106 ><DD
107 ><P
108 >This directive ends the definition of the structure. ENDSTRUCT is the
109 preferred form. Prior to version 3.0 of LWASM, ENDS was used to end a
110 section instead of a structure.</P
111 ></DD
112 ></DL
113 ></DIV
114 ><P
115 >&#13;Within a structure definition, only reservation pseudo ops are permitted.
116 Anything else will cause an assembly error.</P
117 ><P
118 > Once a structure is defined, you can reserve an area of memory in the
119 same structure by using the structure name as the opcode. Structures can
120 also contain fields that are themselves structures. See the example
121 below.</P
122 ><PRE
123 CLASS="PROGRAMLISTING"
124 >tstruct2 STRUCT
125 f1 rmb 1
126 f2 rmb 1
127 ENDSTRUCT
128
129 tstruct STRUCT
130 field1 rmb 2
131 field2 rmb 3
132 field3 tstruct2
133 ENDSTRUCT
134
135 ORG $2000
136 var1 tstruct
137 var2 tstruct2</PRE
138 ><P
139 >Fields are referenced using a dot (.) as a separator. To refer to the
140 generic offset within a structure, use the structure name to the left of the
141 dot. If referring to a field within an actual variable, use the variable's
142 symbol name to the left of the dot.</P
143 ><P
144 >You can also refer to the actual size of a structure (or a variable
145 declared as a structure) using the special symbol sizeof{structname} where
146 structname will be the name of the structure or the name of the
147 variable.</P
148 ><P
149 >Essentially, structures are a shortcut for defining a vast number of
150 symbols. When a structure is defined, the assembler creates symbols for the
151 various fields in the form structname.fieldname as well as the appropriate
152 sizeof{structname} symbol. When a variable is declared as a structure, the
153 assembler does the same thing using the name of the variable. You will see
154 these symbols in the symbol table when the assembler is instructed to
155 provide a listing. For instance, the above listing will create the
156 following symbols (symbol values in parentheses): tstruct2.f1 (0),
157 tstruct2.f2 (1), sizeof{tstruct2} (2), tstruct.field1 (0), tstruct.field2
158 (2), tstruct.field3 (5), tstruct.field3.f1 (5), tstruct.field3.f2 (6),
159 sizeof{tstruct.field3} (2), sizeof{tstruct} (7), var1 {$2000}, var1.field1
160 {$2000}, var1.field2 {$2002}, var1.field3 {$2005}, var1.field3.f1 {$2005},
161 var1.field3.f2 {$2006}, sizeof(var1.field3} (2), sizeof{var1} (7), var2
162 ($2007), var2.f1 ($2007), var2.f2 ($2008), sizeof{var2} (2). </P
163 ></DIV
164 ><DIV
165 CLASS="NAVFOOTER"
166 ><HR
167 ALIGN="LEFT"
168 WIDTH="100%"><TABLE
169 SUMMARY="Footer navigation table"
170 WIDTH="100%"
171 BORDER="0"
172 CELLPADDING="0"
173 CELLSPACING="0"
174 ><TR
175 ><TD
176 WIDTH="33%"
177 ALIGN="left"
178 VALIGN="top"
179 ><A
180 HREF="x562.html"
181 ACCESSKEY="P"
182 >Prev</A
183 ></TD
184 ><TD
185 WIDTH="34%"
186 ALIGN="center"
187 VALIGN="top"
188 ><A
189 HREF="index.html"
190 ACCESSKEY="H"
191 >Home</A
192 ></TD
193 ><TD
194 WIDTH="33%"
195 ALIGN="right"
196 VALIGN="top"
197 ><A
198 HREF="x606.html"
199 ACCESSKEY="N"
200 >Next</A
201 ></TD
202 ></TR
203 ><TR
204 ><TD
205 WIDTH="33%"
206 ALIGN="left"
207 VALIGN="top"
208 >Macros</TD
209 ><TD
210 WIDTH="34%"
211 ALIGN="center"
212 VALIGN="top"
213 ><A
214 HREF="c62.html"
215 ACCESSKEY="U"
216 >Up</A
217 ></TD
218 ><TD
219 WIDTH="33%"
220 ALIGN="right"
221 VALIGN="top"
222 >Object Files and Sections</TD
223 ></TR
224 ></TABLE
225 ></DIV
226 ></BODY
227 ></HTML
228 >