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