Commit | Line | Data |
---|---|---|
d2964941 RH |
1 | .\" |
2 | .\" Copyright (c) 1982 Regents of the University of California | |
c603d1f7 | 3 | .\" @(#)asdocs2.me 1.6 %G% |
d2964941 | 4 | .\" |
2f5c73f2 RH |
5 | .EQ |
6 | delim $$ | |
7 | .EN | |
8 | .SH 1 "Statements" | |
9 | .pp | |
10 | A source program is composed of a sequence of | |
11 | .i statements . | |
12 | Statements are separated either by new-lines | |
13 | or by semicolons. | |
14 | There are two kinds of statements: null statements | |
15 | and keyword statements. | |
16 | Either kind of statement may be preceded by | |
17 | one or more labels. | |
18 | .SH 2 "Named Global Labels" | |
19 | .pp | |
20 | A global label consists of a name followed | |
21 | by a colon. | |
22 | The effect of a name label is to assign the current | |
23 | value and type of the location counter | |
24 | to the name. | |
25 | An error is indicated in pass 1 if the | |
26 | name is already defined; | |
27 | an error is indicated in pass 2 if the | |
28 | value assigned changes the definition | |
29 | of the label. | |
30 | .pp | |
31 | A global label is referenced by its name. | |
32 | .pp | |
33 | Global labels beginning with a | |
34 | .q "\|L\|" | |
35 | are discarded unless the | |
36 | .b \-L | |
37 | option | |
38 | is in effect. | |
39 | .SH 2 "Numeric Local Labels" | |
40 | .pp | |
41 | A numeric label consists of a digit $0$ to $9$ | |
42 | followed by a colon. | |
43 | Such a label serves to define temporary symbols of the form | |
44 | .q "$n roman b$" | |
45 | and | |
46 | .q "$n roman f$" , | |
47 | where $n$ | |
48 | is the digit of the label. | |
49 | As in the case of name labels, | |
50 | a numeric label assigns | |
51 | the current value and type of the location counter | |
52 | to the temporary symbol. | |
53 | However, several numeric labels with the same digit | |
54 | may be used within the same assembly. | |
55 | References to symbols of the form | |
56 | .q "$n roman b$" | |
57 | refer to the first numeric label | |
58 | .q "$n$:" | |
59 | .i b ackwards | |
60 | from the reference; | |
61 | .q "$n roman f$" | |
62 | symbols refer to the first numeric label | |
63 | .q "$n$:" | |
64 | .i f orwards | |
65 | from the reference. | |
66 | Such numeric labels conserve the inventive powers | |
67 | of the human programmer. | |
68 | .pp | |
69 | For various reasons, | |
70 | .i as | |
71 | turns local labels into labels of the form | |
72 | $roman L n roman ".\*(DL" m$. | |
73 | Although unlikely, | |
74 | these generated labels may conflict | |
75 | with programmer defined labels. | |
76 | .SH 2 "Null statements" | |
77 | .pp | |
78 | A null statement is an empty statement ignored by the assembler. | |
79 | A null statement may be labeled, however. | |
80 | .SH 2 "Keyword statements" | |
81 | .pp | |
82 | A keyword statement begins with one of the many predefined | |
83 | keywords known to | |
84 | .i as ; | |
85 | the syntax of the remainder of the statement depends | |
86 | on the keyword. | |
87 | All instruction opcodes are keywords. | |
88 | The remaining keywords are assembler pseudo-operations, | |
89 | also called | |
90 | .i directives . | |
91 | The pseudo-operations are listed in \(sc8, | |
92 | together with the syntax they require. | |
93 | .SH 1 "Expressions" | |
94 | .pp | |
95 | An expression is a sequence of symbols representing a value. | |
96 | Its constituents are identifiers, | |
97 | constants, | |
98 | operators, | |
99 | and parentheses. | |
100 | Each expression has a type. | |
101 | .pp | |
102 | All operators in expressions are fundamentally binary in | |
103 | nature. | |
104 | Arithmetic is two's complement and has 32 bits of precision. | |
105 | .i As | |
106 | can not do arithmetic on floating point numbers, quad or octal | |
107 | precision scalar numbers. | |
108 | There are four levels of precedence, | |
109 | listed here from | |
110 | lowest precedence level to highest: | |
111 | .(b | |
112 | .TS | |
113 | center; | |
114 | c l. | |
115 | precedence operators | |
116 | _ | |
117 | binary $+$, $-$ | |
118 | binary \fI\(bv\fP\|, $&$, $italic "^"$, $!$ | |
119 | binary $*$, $/$, $%$, | |
120 | unary $-$, $italic "~"$ | |
121 | .TE | |
122 | .)b | |
123 | .pp | |
124 | All operators of the same precedence are evaluated strictly left to right, | |
125 | except for the evaluation order enforced by parenthesis. | |
126 | .SH 2 "Expression Operators" | |
127 | .pp | |
128 | The operators are: | |
129 | .(b | |
130 | .TS | |
131 | center; | |
132 | c l. | |
133 | operator meaning | |
134 | _ | |
135 | $+$ addition | |
136 | $-$ (binary) subtraction | |
137 | $*$ multiplication | |
138 | $/$ division | |
139 | $%$ modulo | |
140 | $-$ (unary) 2's complement | |
141 | $&$ bitwise and | |
142 | $\(bv$ bitwise or | |
143 | $italic "^"$ bitwise exclusive or | |
144 | $!$ bitwise or not | |
145 | $italic "~"$ bitwise 1's complement | |
146 | $>$ logical right shift | |
147 | $>>$ logical right shift | |
148 | $<$ logical left shift | |
149 | $<<$ logical left shift | |
150 | .TE | |
151 | .)b | |
152 | .pp | |
153 | Expressions may be grouped by use of parentheses, | |
154 | .q "(" | |
155 | and | |
156 | .q ")". | |
157 | .SH 2 "Data Types" | |
158 | .pp | |
b0ab87d8 | 159 | The assembler manipulates several different |
2f5c73f2 RH |
160 | types of expressions. |
161 | The types likely to be met explicitly are: | |
162 | .nr ii \w'undefined\ \ 'u | |
163 | .ip "undefined" | |
164 | Upon first encounter, | |
165 | each symbol is undefined. | |
166 | It may become undefined if it is assigned an undefined expression. | |
167 | It is an error to attempt to assemble an undefined | |
168 | expression in pass 2; | |
169 | in pass 1, | |
170 | it is not (except that | |
171 | certain keywords require operands which are not undefined). | |
172 | .ip "undefined\ external" | |
173 | A symbol which is declared | |
174 | .b .globl | |
2f5c73f2 RH |
175 | but not defined |
176 | in the current assembly is an undefined external. | |
177 | If such a symbol is declared, | |
178 | the link editor | |
179 | .i ld | |
180 | must be used to load the assembler's output with | |
181 | another routine that defines the undefined reference. | |
182 | .ip "absolute" | |
183 | An absolute symbol is defined ultimately from a constant. | |
184 | Its value is unaffected by any possible future applications | |
185 | of the link-editor to the output file. | |
186 | .ip "text" | |
187 | The value of a text symbol is measured | |
188 | with respect to the beginning of the text segment of the program. | |
189 | If the assembler output is link-edited, | |
190 | its text symbols may change in value | |
191 | since the program need | |
192 | not be the first in the link editor's output. | |
193 | Most text symbols are defined by appearing as labels. | |
194 | At the start of an assembly, | |
195 | the value of | |
196 | .q "\|\fB.\fP\|" | |
197 | is | |
198 | .q "text 0" . | |
199 | .ip "data" | |
200 | The value of a data symbol is measured | |
201 | with respect to the origin of the data segment of a program. | |
202 | Like text symbols, | |
203 | the value of a data symbol may change | |
204 | during a subsequent link-editor run since previously | |
205 | loaded programs may have data segments. | |
206 | After the first | |
207 | .b .data | |
208 | statement, | |
209 | the value of | |
210 | .q "\|\fB.\fP\|" | |
211 | is | |
212 | .q "data 0". | |
213 | .ip "bss" | |
214 | The value of a bss symbol is measured from | |
215 | the beginning of the bss segment of a program. | |
216 | Like text and data symbols, | |
217 | the value of a bss symbol | |
218 | may change during a subsequent link-editor run, | |
219 | since previously loaded programs may have bss segments. | |
220 | .ip "external\ absolute,\ text,\ data,\ or\ bss" | |
b0ab87d8 | 221 | Symbols declared |
2f5c73f2 RH |
222 | .b .globl |
223 | but defined within an assembly as absolute, | |
224 | text, | |
225 | data, | |
226 | or bss | |
227 | symbols may be used exactly as if they were not | |
228 | declared | |
229 | .b .globl ; | |
230 | however, their value and type are available | |
231 | to the link editor so that the program may be loaded with others | |
232 | that reference these symbols. | |
233 | .ip "register" | |
234 | The symbols | |
235 | .(q | |
236 | .b "r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15" | |
237 | .b "ap fp sp pc" | |
238 | .)q | |
239 | are predefined | |
240 | as register symbols. | |
241 | In addition, the | |
242 | .q "%" | |
243 | operator converts the following absolute expression whose | |
244 | value is between 0 and 15 into a register reference. | |
b0ab87d8 | 245 | .ip "other\ types\ \ " |
2f5c73f2 RH |
246 | Each keyword known to the assembler has a type which |
247 | is used to select the routine which processes | |
248 | the associated keyword statement. | |
249 | The behavior of such symbols | |
250 | when not used as keywords is the same as if they were absolute. | |
251 | .SH 2 "Type Propagation in Expressions" | |
252 | .pp | |
253 | When operands are combined by expression operators, | |
254 | the result has a type which depends on the types | |
255 | of the operands and on the operator. | |
256 | The rules involved are complex to state but | |
257 | were intended to be sensible and predictable. | |
258 | For purposes of expression evaluation the | |
259 | important types are | |
260 | .(b | |
261 | .TS | |
262 | center; | |
263 | l. | |
264 | undefined | |
265 | absolute | |
266 | text | |
267 | data | |
268 | bss | |
269 | undefined external | |
270 | other | |
271 | .TE | |
272 | .)b | |
273 | .pp | |
274 | The combination rules are then | |
275 | .nr ii 5n | |
276 | .np | |
277 | If one of the operands is undefined, | |
278 | the result is undefined. | |
279 | .np | |
280 | If both operands are absolute, | |
281 | the result is absolute. | |
282 | .np | |
283 | If an absolute is combined with one of the | |
284 | .q "other types" | |
285 | mentioned above, | |
286 | the result has the other type. | |
287 | An | |
288 | .q "other type" | |
289 | combined with an explicitly | |
290 | discussed type other than absolute | |
291 | it acts like an absolute. | |
292 | .pp | |
293 | Further rules applying to particular operators are: | |
294 | .ip "$+$" | |
295 | If one operand is text-, data-, or bss-segment | |
296 | relocatable, or is an undefined external, | |
297 | the result has the postulated type and the other operand | |
298 | must be absolute. | |
299 | .ip $-$ | |
300 | If the first operand is a relocatable | |
301 | text-, data-, or bss-segment symbol, the second operand | |
302 | may be absolute (in which case the result has the | |
303 | type of the first operand); | |
304 | or the second operand may have the same type | |
305 | as the first (in which case the result is absolute). | |
306 | If the first operand is external undefined, | |
307 | the second must be absolute. | |
308 | All other combinations are illegal. | |
309 | .ip others | |
310 | It is illegal to apply these operators to any but absolute symbols. |