Commit | Line | Data |
---|---|---|
e35d5a7c DR |
1 | .\"tbl ... ^ [tn]roff -ms |
2 | .hc % | |
3 | .TL | |
4 | Assembler Reference Manual | |
5 | .AU | |
6 | Dennis M. Ritchie | |
7 | .AI | |
8 | .MH | |
9 | .SH | |
10 | 0. Introduction | |
11 | .PP | |
12 | This document describes the usage and input syntax | |
13 | of the \s8UNIX PDP\s10-11 assembler \fIas\fP. | |
14 | The details | |
15 | of the \s8PDP\s10-11 are not described. | |
16 | .PP | |
17 | The input syntax of the \s8UNIX\s10 assembler is generally | |
18 | similar to that of the \s8DEC\s10 assembler \s8PAL\s10-11\s8R\s10, although | |
19 | its internal workings and output format | |
20 | are unrelated. | |
21 | It may be useful to read the publication \s8DEC\s10-11-\s8ASDB\s10-\s8D\s10, | |
22 | which describes \s8PAL\s10-11\s8R\s10, although naturally | |
23 | one must use care in assuming that its rules apply | |
24 | to \fIas\fP. | |
25 | .PP | |
26 | \fIAs\fP is a rather ordinary assembler without | |
27 | macro capabilities. | |
28 | It produces an output file that contains | |
29 | relocation information and a complete | |
30 | symbol table; | |
31 | thus the output is acceptable to the \s8UNIX\s10 link-editor | |
32 | \fIld\fP, which | |
33 | may be used to combine the outputs of several | |
34 | assembler runs and to obtain | |
35 | object programs from libraries. | |
36 | The output format has been designed | |
37 | so that if a program contains no unresolved | |
38 | ref%er%ences to external symbols, it is executable | |
39 | without further processing. | |
40 | .SH | |
41 | 1. Usage | |
42 | .PP | |
43 | \fIas\fP is used as follows: | |
44 | .DS | |
45 | as \fR[\fB \-u \fR] [ \fB\-o \fIoutput\fR ] \fIfile\s6\d1\u\s10 .\|.\|. | |
46 | .DE | |
47 | If the optional ``\-u'' argument is | |
48 | given, all undefined symbols | |
49 | in the current assembly will be made undefined-external. | |
50 | See the \fB.globl\fR directive below. | |
51 | .PP | |
52 | The other arguments name files | |
53 | which are concatenated and assembled. | |
54 | Thus programs may be written in several | |
55 | pieces and assembled together. | |
56 | .PP | |
57 | The output of the assembler is by default placed on | |
58 | the file \fIa.out\fR in the current directory; | |
59 | the ``\-o'' flag causes the output to be placed on the named file. | |
60 | If there were no unresolved | |
61 | external ref%er%ences, and no errors detected, | |
62 | the output file is marked executable; otherwise, if it is | |
63 | produced at all, it is made non-executable. | |
64 | .SH | |
65 | 2. Lexical conventions | |
66 | .PP | |
67 | Assembler tokens include identifiers (alternatively, ``symbols'' or ``names''), | |
68 | temporary symbols, | |
69 | constants, and operators. | |
70 | .SH | |
71 | 2.1 Identifiers | |
72 | .PP | |
73 | An identifier consists of a sequence of alphanumeric characters (including | |
74 | period ``\|\fB.\fR\|'', underscore ``\(ul'', | |
75 | and tilde ``~'' | |
76 | as alphanumeric) | |
77 | of which the first may not | |
78 | be numeric. | |
79 | Only the first eight characters are significant. | |
80 | When a name begins with a tilde, the tilde is discarded | |
81 | and that occurrence of the identifier generates | |
82 | a unique entry in the symbol table which can match | |
83 | no other occurrence of the identifier. | |
84 | This feature is used | |
85 | by the C compiler to place names of local variables | |
86 | in the output symbol table | |
87 | without having to worry | |
88 | about | |
89 | making them unique. | |
90 | .SH | |
91 | 2.2 Temporary symbols | |
92 | .PP | |
93 | A temporary symbol consists of a digit followed by ``f\|'' or | |
94 | ``b''. | |
95 | Temporary symbols are discussed fully in \(sc5.1. | |
96 | .SH | |
97 | 2.3 Constants | |
98 | .PP | |
99 | An octal constant consists of a sequence of digits; ``8'' and | |
100 | ``9'' are taken to have octal value 10 and 11. | |
101 | The constant | |
102 | is truncated to 16 bits and interpreted in two's complement | |
103 | notation. | |
104 | .PP | |
105 | A decimal constant consists of a sequence of digits terminated | |
106 | by a decimal point ``\fB.\fR''. The magnitude of the constant should be | |
107 | representable in 15 bits; i.e., be less than 32,768. | |
108 | .PP | |
109 | A single-character constant consists of a single quote ``\|\(fm\|'' | |
110 | followed by an \s8ASCII\s10 character not a new-line. | |
111 | Certain dual-character escape sequences | |
112 | are acceptable in place of the \s8ASCII\s10 character to represent | |
113 | new-line and other non-graphics (see \fIString state%ments\fP, \(sc5.5). | |
114 | The constant's value has the code for the | |
115 | given character in the least significant | |
116 | byte of the word and is null-padded on the left. | |
117 | .PP | |
118 | A double-character constant consists of a double | |
119 | quote ``\|"\|'' followed by a pair of \s8ASCII\s10 characters | |
120 | not including new-line. | |
121 | Certain dual-character escape sequences are acceptable | |
122 | in place of either of the \s8ASCII\s10 characters | |
123 | to represent new-line and other non-graphics | |
124 | (see \fIString state%ments\fR, \(sc5.5). | |
125 | The constant's value has the code for the first | |
126 | given character in the least significant | |
127 | byte and that for the second character in | |
128 | the most significant byte. | |
129 | .SH | |
130 | 2.4 Operators | |
131 | .PP | |
132 | There are several single- and double-character | |
133 | operators; see \(sc6. | |
134 | .SH | |
135 | 2.5 Blanks | |
136 | .PP | |
137 | Blank and tab characters | |
138 | may be interspersed freely between tokens, but may | |
139 | not be used within tokens (except character constants). | |
140 | A blank or tab is required to separate adjacent | |
141 | identifiers or constants not otherwise separated. | |
142 | .SH | |
143 | 2.6 Comments | |
144 | .PP | |
145 | The character ``\|/\|'' introduces a comment, which extends | |
146 | through the end of the line on which it appears. | |
147 | Comments are ignored by the assembler. | |
148 | .SH | |
149 | 3. Segments | |
150 | .PP | |
151 | Assembled code and data | |
152 | fall into three segments: the text segment, the data segment, and the bss segment. | |
153 | The text segment is the one in which the assembler begins, | |
154 | and it is the one into which instructions are typically placed. | |
155 | The \s8UNIX\s10 system will, if desired, | |
156 | enforce the purity of the text segment of programs by | |
157 | trapping write operations | |
158 | into it. | |
159 | Object programs produced by the assembler must be processed | |
160 | by the link-editor \fIld\fR | |
161 | (using its ``\-n'' flag) | |
162 | if the text segment is to be write-protected. | |
163 | A single copy of the text | |
164 | segment is shared among all processes | |
165 | executing such a program. | |
166 | .PP | |
167 | The data segment is available for placing | |
168 | data or instructions which | |
169 | will be modified during execution. | |
170 | Anything which may go in the text segment may be put | |
171 | into the data segment. | |
172 | In programs with write-protected, sharable text segments, | |
173 | data segment contains the initialized but variable | |
174 | parts of a program. | |
175 | If the text segment is not pure, the data segment begins | |
176 | immediately after the | |
177 | text segment; | |
178 | if the text segment is pure, the data segment begins at the lowest | |
179 | 8K byte boundary after the text segment. | |
180 | .PP | |
181 | The bss segment may not contain any explicitly initialized code | |
182 | or data. | |
183 | The length of the bss segment (like that of text or data) | |
184 | is determined by the high-water mark of the location counter | |
185 | within it. | |
186 | The bss segment is actually an extension of | |
187 | the data segment and begins immediately after it. | |
188 | At the start of execution of a program, the bss segment | |
189 | is set to 0. | |
190 | Typically the bss segment is set up | |
191 | by state%ments exemplified by | |
192 | .DS | |
193 | lab\fB: .\fR = \fB.\fR+10 | |
194 | .DE | |
195 | The advantage in using the bss segment | |
196 | for storage that starts off empty is that the initialization | |
197 | information need not be stored in the output file. | |
198 | See also \fILocation counter\fP and \fIAssignment state%ments\fP | |
199 | below. | |
200 | .SH | |
201 | 4. The location counter | |
202 | .PP | |
203 | One special symbol, ``\|\fB.\fP\|'', is the location counter. | |
204 | Its value at any time is the offset | |
205 | within the appropriate segment of the start of | |
206 | the state%ment in which it appears. | |
207 | The location counter may be assigned to, | |
208 | with the restriction that the | |
209 | current segment may not change; | |
210 | furthermore, | |
211 | the value of ``\|\fB.\fP\|'' may not decrease. | |
212 | If the effect of the assignment is to increase the value of ``\|\fB.\fP\|'', | |
213 | the required number of null bytes are generated | |
214 | (but see \fISegments\fP above). | |
215 | .SH | |
216 | 5. Statements | |
217 | .PP | |
218 | A source program is composed of a sequence of | |
219 | \fIstate%ments\fP. | |
220 | Statements are separated either by new-lines | |
221 | or by semicolons. | |
222 | There are five kinds of state%ments: null state%ments, | |
223 | expression state%ments, assignment state%ments, | |
224 | string state%ments, | |
225 | and keyword state%ments. | |
226 | .PP | |
227 | Any kind of state%ment may be preceded by | |
228 | one or more labels. | |
229 | .SH | |
230 | 5.1 Labels | |
231 | .PP | |
232 | There are two kinds of label: | |
233 | name labels and numeric labels. | |
234 | A name label consists of a name followed | |
235 | by a colon (\|:\|). | |
236 | The effect of a name label is to assign the current | |
237 | value and type of the location counter ``\|\fB.\fP\|'' | |
238 | to the name. | |
239 | An error is indicated in pass 1 if the | |
240 | name is already defined; | |
241 | an error is indicated in pass 2 if the ``\|\fB.\fP\|'' | |
242 | value assigned changes the definition | |
243 | of the label. | |
244 | .PP | |
245 | A numeric label consists of a digit \fI0\fR to \fI9\fR followed by a colon (\|:\|). | |
246 | Such a label serves to define temporary | |
247 | symbols of the form ``\fIn\fR\|b'' and ``\fIn\fR\|f\|'', where \fIn\fR is | |
248 | the digit of the label. | |
249 | As in the case of name labels, a numeric label assigns | |
250 | the current value and type of ``\|\fB.\fP\|'' to the temporary | |
251 | symbol. | |
252 | However, several numeric labels with the same | |
253 | digit may be used within the same assembly. | |
254 | Ref%er%ences of the form ``\fIn\fR\|f\|'' refer to the first | |
255 | numeric label ``\fIn\|\fR:'' \fIf\fR\|orward from the ref%er%ence; | |
256 | ``\fIn\|\fRb'' symbols refer to the first ``\fIn\|\fR\|:'' label | |
257 | \fIb\|\fRackward from the ref%er%ence. | |
258 | This sort of temporary label was introduced by Knuth | |
259 | [\fIThe Art of Computer Programming, Vol I: Fundamental Algorithms\|\fR]. | |
260 | Such labels tend to conserve both the symbol table | |
261 | space of the assembler and the | |
262 | inventive powers of the programmer. | |
263 | .SH | |
264 | 5.2 Null state%ments | |
265 | .PP | |
266 | A null state%ment is an empty state%ment (which may, however, | |
267 | have labels). | |
268 | A null state%ment is ignored by the assembler. | |
269 | Common examples of null state%ments are empty | |
270 | lines or lines containing only a label. | |
271 | .SH | |
272 | 5.3 Expression state%ments | |
273 | .PP | |
274 | An expression state%ment consists of an arithmetic | |
275 | expression not beginning with | |
276 | a keyword. | |
277 | The assembler computes its (16-bit) value | |
278 | and places it in the output stream, together with the | |
279 | appropriate relocation bits. | |
280 | .SH | |
281 | 5.4 Assignment state%ments | |
282 | .PP | |
283 | An assignment state%ment consists of an identifier, an equals sign (\|=\|), | |
284 | and an expression. | |
285 | The value and type of the expression are assigned to | |
286 | the identifier. | |
287 | It is not required that the type or value be | |
288 | the same in pass 2 as in pass 1, nor is it an | |
289 | error to redefine any symbol by assignment. | |
290 | .PP | |
291 | Any external attribute of the expression is lost across | |
292 | an assignment. | |
293 | This means that it is not possible to declare a global | |
294 | symbol by assigning to it, and that it is impossible | |
295 | to define a symbol to be offset from a non-locally | |
296 | defined global symbol. | |
297 | .PP | |
298 | As mentioned, | |
299 | it is permissible to assign to the | |
300 | location counter ``\|\fB.\fP\|''. | |
301 | It is required, however, that the type of | |
302 | the expression assigned be of the same type | |
303 | as ``\|\fB.\fP\|'', | |
304 | and it is forbidden to decrease the value | |
305 | of ``\fB\|.\|\fR''. | |
306 | In practice, the most common assignment to ``\|\fB.\fP\|'' has the form | |
307 | ``.\|=\|.\|+\|\fIn\fR'' | |
308 | for some number \fIn;\fR this has the effect of generating | |
309 | \fIn\fR null bytes. | |
310 | .SH | |
311 | 5.5 String state%ments | |
312 | .PP | |
313 | A string state%ment generates a sequence of bytes containing \s8ASCII\s10 characters. | |
314 | A string state%ment consists of a left string quote ``<'' | |
315 | followed by a sequence of \s8ASCII\s10 characters not including newline, | |
316 | followed by a right string quote ``>''. | |
317 | Any of the \s8ASCII\s10 characters may | |
318 | be replaced by a two-character escape sequence to represent | |
319 | certain non-graphic characters, as follows: | |
320 | .DS C | |
321 | .TS | |
322 | l l l. | |
323 | \en \s8NL\s10 (012) | |
324 | \es \s8SP\s10 (040) | |
325 | \et \s8HT\s10 (011) | |
326 | \ee \s8EOT\s10 (004) | |
327 | \e0 \s8NUL\s10 (000) | |
328 | \er \s8CR\s10 (015) | |
329 | \ea \s8ACK\s10 (006) | |
330 | \ep \s8PFX\s10 (033) | |
331 | \e\e \e | |
332 | \e> > | |
333 | .TE | |
334 | .DE | |
335 | The last two are included so that the escape character | |
336 | and the right string quote may be represented. | |
337 | The same escape sequences | |
338 | may also be used within single- and double-character | |
339 | constants (see \(sc2.3 above). | |
340 | .SH | |
341 | 5.6 Keyword state%ments | |
342 | .PP | |
343 | Keyword state%ments are numerically the most common type, | |
344 | since most machine instructions are of this | |
345 | sort. | |
346 | A keyword state%ment begins with one of the many predefined | |
347 | keywords of the assembler; | |
348 | the syntax of the remainder depends | |
349 | on the keyword. | |
350 | All the keywords are listed below with the syntax they require. | |
351 | .SH | |
352 | 6. Expressions | |
353 | .PP | |
354 | An expression is a sequence of symbols representing a value. | |
355 | Its constituents are identifiers, constants, temporary symbols, | |
356 | operators, and brackets. | |
357 | Each expression has a type. | |
358 | .PP | |
359 | All operators in expressions are fundamentally binary in | |
360 | nature; if an operand is missing on the left, a 0 | |
361 | of absolute type is assumed. | |
362 | Arithmetic | |
363 | is two's complement and has 16 bits of precision. | |
364 | All operators have equal precedence, and expressions | |
365 | are evaluated | |
366 | strictly left to right except for the effect | |
367 | of brackets. | |
368 | .SH | |
369 | 6.1 Expression operators | |
370 | .PP | |
371 | The operators are: | |
372 | .IP (blank) 8 | |
373 | when there is no operand between | |
374 | operands, the effect is | |
375 | exactly the same as if a ``+'' had appeared. | |
376 | .pg | |
377 | .ti 0 | |
378 | .IP + 8 | |
379 | addition | |
380 | .IP \- 8 | |
381 | subtraction | |
382 | .IP * 8 | |
383 | multiplication | |
384 | .IP \e\(sl 8 | |
385 | division (note that plain ``\|/\|'' starts a comment) | |
386 | .IP 8 & 8 | |
387 | bitwise \fBand\fR | |
388 | .IP \(bv 8 | |
389 | bitwise \fBor\fR | |
390 | .IP \e> 8 | |
391 | logical right shift | |
392 | .IP \\e< 8 | |
393 | logical left shift | |
394 | .hc | |
395 | .IP % 8 | |
396 | modulo | |
397 | .IP ! 8 | |
398 | .hc % | |
399 | \fIa\fR\|!\|\fIb\fR is \fIa \fBor \fR(\|\fBnot \fIb\fR\|); | |
400 | i.e., the \fBor\fR of the first operand and | |
401 | the one's complement of the second; most common use is | |
402 | as a unary. | |
403 | .IP ^ 8 | |
404 | result has the value of first operand and the type of the second; | |
405 | most often used to define new machine instructions | |
406 | with syntax identical to existing instructions. | |
407 | .PP | |
408 | Expressions may be grouped by use of square brackets ``\|[\|\|]\|''. | |
409 | (Round parentheses are reserved for address modes.) | |
410 | .SH | |
411 | 6.2 Types | |
412 | .PP | |
413 | The assembler deals with a number of types | |
414 | of expressions. Most types | |
415 | are attached to keywords and used to select the | |
416 | routine which treats that keyword. The types likely | |
417 | to be met explicitly are: | |
418 | .IP undefined 8 | |
419 | .br | |
420 | Upon first encounter, each symbol is undefined. | |
421 | It may become undefined if it is assigned an undefined expression. | |
422 | It is an error to attempt to assemble an undefined | |
423 | expression in pass 2; in pass 1, it is not (except that | |
424 | certain keywords require operands which are not undefined). | |
425 | .IP "undefined external" 8 | |
426 | .br | |
427 | A symbol which is declared \fB.globl\fR but not defined | |
428 | in the current assembly is an undefined | |
429 | external. | |
430 | If such a symbol is declared, the link editor \fIld\fR | |
431 | must be used to load the assembler's output with | |
432 | another routine that defines the undefined ref%er%ence. | |
433 | .IP absolute 8 | |
434 | An absolute symbol is defined ultimately from a constant. | |
435 | Its value is unaffected by any possible future applications | |
436 | of the link-editor to the output file. | |
437 | .IP text 8 | |
438 | The value of a text symbol is measured | |
439 | with respect to the beginning of the text segment of the program. | |
440 | If the assembler output is link-edited, its text | |
441 | symbols may change in value | |
442 | since the program need | |
443 | not be the first in the link editor's output. | |
444 | Most text symbols are defined by appearing as labels. | |
445 | At the start of an assembly, the value of ``\|\fB.\fP\|'' is text 0. | |
446 | .IP data 8 | |
447 | The value of a data symbol is measured | |
448 | with respect to the origin of the data segment of a program. | |
449 | Like text symbols, the value of a data symbol may change | |
450 | during a subsequent link-editor run since previously | |
451 | loaded programs may have data segments. | |
452 | After the first \fB.data\fR state%ment, the value of ``\|\fB.\fP\|'' | |
453 | is data 0. | |
454 | .IP bss 8 | |
455 | The value of a bss symbol is measured from | |
456 | the beginning of the bss segment of a program. | |
457 | Like text and data symbols, the value of a bss symbol | |
458 | may change during a subsequent link-editor | |
459 | run, since previously loaded programs may have bss segments. | |
460 | After the first \fB.bss\fR state%ment, the value of ``\|\fB.\fP\|'' is bss 0. | |
461 | .IP "external absolute, text, data, or bss" 8 | |
462 | .br | |
463 | symbols declared \fB.globl\fR | |
464 | but defined within an assembly as absolute, text, data, or bss | |
465 | symbols may be used exactly as if they were not | |
466 | declared \fB.globl\fR; however, their value and type are available | |
467 | to the link editor so that the program may be loaded with others | |
468 | that ref%er%ence these symbols. | |
469 | .IP register 8 | |
470 | .br | |
471 | The symbols | |
472 | .DS | |
473 | \fBr0\fR .\|.\|. \fBr5 | |
474 | fr0\fR .\|.\|. \fBfr5 | |
475 | sp | |
476 | pc | |
477 | .DE | |
478 | are predefined | |
479 | as register symbols. | |
480 | Either they or symbols defined from them must | |
481 | be used to refer to the six general-purpose, | |
482 | six floating-point, and | |
483 | the 2 special-purpose machine registers. | |
484 | The behavior of the floating register names | |
485 | is identical to that of the corresponding | |
486 | general register names; the former | |
487 | are provided as a mnemonic aid. | |
488 | .IP "other types" 8 | |
489 | .br | |
490 | Each keyword known to the assembler has a type which | |
491 | is used to select the routine which processes | |
492 | the associated keyword state%ment. | |
493 | The behavior of such symbols | |
494 | when not used as keywords is the same as if they were absolute. | |
495 | .SH | |
496 | 6.3 Type propagation in expressions | |
497 | .PP | |
498 | When operands are combined by expression operators, | |
499 | the result has a type which depends on the types | |
500 | of the operands and on the operator. | |
501 | The rules involved are complex to state but | |
502 | were intended to be sensible and predictable. | |
503 | For purposes of expression evaluation the | |
504 | important types are | |
505 | .DS | |
506 | undefined | |
507 | absolute | |
508 | text | |
509 | data | |
510 | bss | |
511 | undefined external | |
512 | other | |
513 | .DE | |
514 | The combination rules are then: | |
515 | If one of the operands | |
516 | is undefined, the result is undefined. | |
517 | If both operands are absolute, the result is absolute. | |
518 | If an absolute is combined with one of the ``other types'' | |
519 | mentioned above, | |
520 | or with a register expression, the result | |
521 | has the register or other type. | |
522 | As a consequence, | |
523 | one can refer to r3 as ``r0+3''. | |
524 | If two operands of ``other type'' are combined, | |
525 | the result has the | |
526 | numerically larger type | |
527 | An ``other type'' combined with an explicitly | |
528 | discussed type other than absolute | |
529 | acts like an absolute. | |
530 | .PP | |
531 | Further rules applying to particular operators | |
532 | are: | |
533 | .IP + | |
534 | If one operand is text-, data-, or bss-segment | |
535 | relocatable, or is an undefined external, | |
536 | the result has the postulated type and the other operand | |
537 | must be absolute. | |
538 | .IP \- | |
539 | If the first operand is a relocatable | |
540 | text-, data-, or bss-segment symbol, the second operand | |
541 | may be absolute (in which case the result has the | |
542 | type of the first operand); | |
543 | or the second operand may have the same type | |
544 | as the first (in which case the result is absolute). | |
545 | If the first operand is external undefined, the second must be | |
546 | absolute. | |
547 | All other combinations are illegal. | |
548 | .IP ^ | |
549 | This operator follows no other rule than | |
550 | that the result has the value | |
551 | of the first operand and the type of the second. | |
552 | .PP | |
553 | .IP others | |
554 | .br | |
555 | It is illegal to apply these operators to any but absolute | |
556 | symbols. | |
557 | .SH | |
558 | 7. Pseudo-operations | |
559 | .PP | |
560 | The keywords listed below introduce | |
561 | state%ments that generate data in unusual forms or | |
562 | influence the later operations of the assembler. | |
563 | The metanotation | |
564 | .DS | |
565 | [ stuff ] .\|.\|. | |
566 | .DE | |
567 | means that 0 or more instances of the given stuff may appear. | |
568 | Also, boldface tokens are literals, italic words | |
569 | are substitutable. | |
570 | .SH | |
571 | 7.1 \fB.byte \fIexpression \fR[ \fB, \fIexpression \fR] .\|.\|. | |
572 | .PP | |
573 | The \fIexpression\fRs in the comma-separated | |
574 | list are truncated to 8 bits and assembled in successive | |
575 | bytes. | |
576 | The expressions must be absolute. | |
577 | This state%ment and the string state%ment above are the only ones | |
578 | that assemble data one byte at at time. | |
579 | .SH | |
580 | 7.2 \fB.even\fR | |
581 | .PP | |
582 | If the location counter ``\|\fB.\fP\|'' is odd, it is advanced by one | |
583 | so the next state%ment will be assembled | |
584 | at a word boundary. | |
585 | .SH | |
586 | 7.3 \fB.if \fIexpression\fR | |
587 | .PP | |
588 | The \fIexpression\fR must be absolute and defined in pass 1. | |
589 | If its value is nonzero, the \fB.if\fR is ignored; if zero, | |
590 | the state%ments between the \fB.if\fR and the matching \fB.endif\fR | |
591 | (below) are ignored. | |
592 | \&\fB.if\fR may be nested. | |
593 | The effect of \fB.if\fR cannot extend beyond | |
594 | the end of the input file in which it appears. | |
595 | (The state%ments are not totally ignored, in | |
596 | the following | |
597 | sense: \fB.if\fRs and \fB.endif\fRs are scanned for, and | |
598 | moreover all names | |
599 | are entered in the symbol table. | |
600 | Thus names occurring only inside | |
601 | an \fB.if\fR | |
602 | will show up as undefined if the symbol | |
603 | table is listed.) | |
604 | .SH | |
605 | 7.4 \fB.endif\fR | |
606 | .PP | |
607 | This state%ment marks the end of a conditionally-assembled section of code. | |
608 | See \fB.if\fR above. | |
609 | .SH | |
610 | 7.5 \fB.globl \fIname \fR[ \fB,\fI name \fR] .\|.\|. | |
611 | .PP | |
612 | This state%ment makes the \fInames\fR external. | |
613 | If they are otherwise defined (by assignment or | |
614 | appearance as a label) | |
615 | they act within the assembly exactly as if | |
616 | the \fB.globl\fR state%ment were not given; however, | |
617 | the link editor \fIld\fR may be used | |
618 | to combine this routine with other routines that refer | |
619 | these symbols. | |
620 | .PP | |
621 | Conversely, if the given symbols are not defined | |
622 | within the current assembly, the link editor | |
623 | can combine the output of this assembly | |
624 | with that of others which define the symbols. | |
625 | As discussed in \(sc1, it is possible to force | |
626 | the assembler to make all otherwise | |
627 | undefined symbols external. | |
628 | .SH | |
629 | 7.6 \fB.text\fR | |
630 | .SH | |
631 | 7.7 \fB.data\fR | |
632 | .SH | |
633 | 7.8 \fB.bss\fR | |
634 | .PP | |
635 | These three pseudo-operations cause the | |
636 | assembler to begin assembling into the text, data, or | |
637 | bss segment respectively. | |
638 | Assembly starts in the text segment. | |
639 | It is forbidden to assemble any | |
640 | code or data into the bss segment, but symbols may | |
641 | be defined and ``\|\fB.\fP\|'' moved about by assignment. | |
642 | .SH | |
643 | 7.9 \fB.comm\fI name \fB, \fIexpression\fR | |
644 | .PP | |
645 | Provided the \fIname\fR is not defined elsewhere, | |
646 | this state%ment is equivalent to | |
647 | .DS | |
648 | \&.globl name | |
649 | name = expression ^ name | |
650 | .DE | |
651 | That is, the type of \fIname\fR | |
652 | is ``undefined external'', and its value is \fIexpression\fR. | |
653 | In fact the \fIname\fR behaves | |
654 | in the current assembly just like an | |
655 | undefined external. | |
656 | However, the link-editor \fIld\fR has been special-cased | |
657 | so that all external symbols which are not | |
658 | otherwise defined, and which have a non-zero | |
659 | value, are defined to lie in the bss | |
660 | segment, and enough space is left after the | |
661 | symbol to hold \fIexpression\fR | |
662 | bytes. | |
663 | All symbols which become defined in this way | |
664 | are located before all the explicitly defined | |
665 | bss-segment locations. | |
666 | .SH | |
667 | 8. Machine instructions | |
668 | .PP | |
669 | Because of the rather complicated instruction and addressing | |
670 | structure of the \s8PDP\s10-11, the syntax of machine instruction | |
671 | state%ments is varied. | |
672 | Although the following sections give the syntax | |
673 | in detail, the machine handbooks should | |
674 | be consulted on the semantics. | |
675 | .SH | |
676 | 8.1 Sources and Destinations | |
677 | .PP | |
678 | The syntax of general source and destination | |
679 | addresses is the same. | |
680 | Each must have one of the following forms, | |
681 | where \fIreg\fR is a register symbol, and \fIexpr\fR | |
682 | is any sort of expression: | |
683 | .DS C | |
684 | .TS | |
685 | c c c | |
686 | l l l. | |
687 | syntax words mode | |
688 | _ | |
689 | \fIreg\fR 0 00+\fIreg\fB | |
690 | (\|\fIreg\fB\|)\|+ \fR0 20+\fIreg\fB | |
691 | \fB\-\|(\|\fIreg\fB\|) \fR0 40+\fIreg\fR | |
692 | \fIexpr\|\fB(\|\fIreg\fB\|) \fR1 60+\fIreg\fB | |
693 | (\|\fIreg\fB\|) \fR0 10+\fIreg\fB | |
694 | *\|\fIreg\fB \fR0 10+\fIreg\fB | |
695 | \fB*\|(\|\fIreg\fB\|)\|+ \fR0 30+\fIreg\fB | |
696 | \fB*\|\-\|(\|\fIreg\fB\|) \fR0 50+\fIreg\fB | |
697 | *\|(\|\fIreg\fB\|) \fR1 70+\fIreg\fB | |
698 | \fB*\|\fIexpr\fB\|(\|\fIreg\fB\|) \fR1 70+\fIreg\fB | |
699 | \fIexpr \fR1 67 | |
700 | \fB$\|\fIexpr \fR1 27 | |
701 | \fB*\|\fIexpr \fR1 77 | |
702 | \fB*\|$\|\fIexpr \fR1 37 | |
703 | .TE | |
704 | .DE | |
705 | The \fIwords\fR column gives the number of address words generated; | |
706 | the \fImode\fR column gives the octal address-mode number. | |
707 | The syntax of the address forms is | |
708 | identical to that in \s8DEC\s10 assemblers, except that ``*'' has | |
709 | been substituted for ``@'' | |
710 | and ``$'' for ``#''; the \s8UNIX\s10 typing conventions make ``@'' and ``#'' | |
711 | rather inconvenient. | |
712 | .PP | |
713 | Notice that mode ``*reg'' is identical to ``(reg)''; | |
714 | that ``*(reg)'' generates an index word (namely, 0); | |
715 | and that addresses consisting of an unadorned expression | |
716 | are assembled as pc-relative ref%er%ences independent | |
717 | of the type of the expression. | |
718 | To force a non-relative ref%er%ence, the form ``*$expr'' can | |
719 | be used, but notice that further indirection is impossible. | |
720 | .SH | |
721 | 8.3 Simple machine instructions | |
722 | .PP | |
723 | The following instructions | |
724 | are defined as absolute symbols: | |
725 | .KS | |
726 | .DS | |
727 | .ft B | |
728 | clc | |
729 | clv | |
730 | clz | |
731 | cln | |
732 | sec | |
733 | sev | |
734 | sez | |
735 | sen | |
736 | .DE | |
737 | .KE | |
738 | They therefore require | |
739 | no special syntax. | |
740 | The \s8PDP\s10-11 hardware allows more than one of the ``clear'' | |
741 | class, or alternatively more than one of the ``set'' class | |
742 | to be \fBor\fR-ed together; this may be expressed as follows: | |
743 | .DS | |
744 | clc\|\|\|\(bv\|\|clv | |
745 | .DE | |
746 | .SH | |
747 | 8.4 Branch | |
748 | .PP | |
749 | The following instructions take an expression as operand. | |
750 | The expression must lie in the same segment as the ref%er%ence, | |
751 | cannot be undefined-external, | |
752 | and its value cannot differ from the current location of ``\|\fB.\fP\|'' | |
753 | by more than 254 bytes: | |
754 | .KS | |
755 | .DS | |
756 | .ft B | |
757 | .ta 1.5i 2.5i | |
758 | br blos | |
759 | bne bvc | |
760 | beq bvs | |
761 | bge bhis | |
762 | blt bec \fR(=\fB bcc\fR)\fB | |
763 | bgt bcc | |
764 | ble blo | |
765 | bpl bcs | |
766 | bmi bes \fR(=\fB bcs\fR)\fB | |
767 | bhi | |
768 | .DE | |
769 | .KE | |
770 | \fBbes\fR (``branch on error set'') | |
771 | and \fBbec\fR (``branch on error clear'') | |
772 | are intended to test the error bit | |
773 | returned by system calls (which | |
774 | is the c-bit). | |
775 | .SH | |
776 | 8.5 Extended branch instructions | |
777 | .PP | |
778 | The following symbols are followed by an expression | |
779 | representing an address | |
780 | in the same segment as ``\|\fB.\|\fP''. | |
781 | If the target address is close enough, | |
782 | a branch-type instruction is generated; | |
783 | if the address is too far away, | |
784 | a \fBjmp\fR will be used. | |
785 | .pg | |
786 | .KS | |
787 | .DS | |
788 | .ft B | |
789 | .ta 1.5i | |
790 | jbr jlos | |
791 | jne jvc | |
792 | jeq jvs | |
793 | jge jhis | |
794 | jlt jec | |
795 | jgt jcc | |
796 | jle jlo | |
797 | jpl jcs | |
798 | jmi jes | |
799 | jhi | |
800 | .DE | |
801 | .KE | |
802 | \fBjbr\fR turns into a plain \fBjmp\fR | |
803 | if its target is too remote; | |
804 | the others (whose names are contructed | |
805 | by replacing the ``b'' in the branch instruction's | |
806 | name by ``j''\|) | |
807 | turn into the converse branch over a \fBjmp\fR | |
808 | to the target address. | |
809 | .SH | |
810 | 8.6 Single operand instructions | |
811 | .PP | |
812 | The following | |
813 | symbols are names of single-operand | |
814 | machine instructions. | |
815 | The form | |
816 | of address expected is discussed in \(sc8.1 above. | |
817 | .KS | |
818 | .DS | |
819 | .ta 1.5i | |
820 | clr sbcb | |
821 | clrb ror | |
822 | com rorb | |
823 | comb rol | |
824 | inc rolb | |
825 | incb asr | |
826 | dec asrb | |
827 | decb asl | |
828 | neg aslb | |
829 | negb jmp | |
830 | adc swab | |
831 | adcb tst | |
832 | sbc tstb | |
833 | .DE | |
834 | .KE | |
835 | .SH | |
836 | 8.7 Double operand instructions | |
837 | .PP | |
838 | The following instructions take a general source | |
839 | and destination (\(sc8.1), separated by a comma, as operands. | |
840 | .KS | |
841 | .DS | |
842 | .ft B | |
843 | .ta 1.5i | |
844 | mov | |
845 | movb | |
846 | cmp | |
847 | cmpb | |
848 | bit | |
849 | bitb | |
850 | bic | |
851 | bicb | |
852 | bis | |
853 | bisb | |
854 | add | |
855 | sub | |
856 | .DE | |
857 | .KE | |
858 | .SH | |
859 | 8.8 Miscellaneous instructions | |
860 | .PP | |
861 | The following instructions have | |
862 | more specialized syntax. | |
863 | Here \fIreg\fR is | |
864 | a register name, \fIsrc\fR and \fIdst\fR a general source | |
865 | or destination | |
866 | (\(sc8.1), and \fIexpr\fR is an expression: | |
867 | .KS | |
868 | .DS | |
869 | .ta .5i 2i | |
870 | \fBjsr\fI reg,dst | |
871 | \fBrts\fI reg | |
872 | \fBsys\fI expr | |
873 | \fBash \fIsrc\|,\|reg \fR(or, \fBals\fR)\fB | |
874 | \fBashc \fIsrc\|,\|reg \fR(or, \fBalsc\fR)\fB | |
875 | \fBmul \fIsrc\|,\|reg \fR(or, \fBmpy\fR)\fB | |
876 | \fBdiv \fIsrc\|,\|reg \fR(or, \fBdvd\fR)\fR | |
877 | \fBxor \fIreg\|,\|dst\fB | |
878 | \fBsxt \fIdst\fB | |
879 | \fBmark \fIexpr\fB | |
880 | \fBsob \fIreg\|,\|expr\fB | |
881 | .DE | |
882 | .KE | |
883 | \fBsys\fR is another name for the \fBtrap\fR instruction. | |
884 | It is used to code system calls. | |
885 | Its operand is required to be expressible in 6 bits. | |
886 | The expression in \fBmark\fR must be expressible | |
887 | in six bits, and the expression in \fBsob\fR must | |
888 | be in the same segment as ``\fB\|.\|\fR'', | |
889 | must not be external-undefined, must be less than ``\|\fB.\fR\|'', | |
890 | and must be within 510 bytes of ``\|\fB.\fR\|''. | |
891 | .SH | |
892 | 8.9 Floating-point unit instructions | |
893 | .PP | |
894 | The following floating-point operations are defined, | |
895 | with syntax as indicated: | |
896 | .KS | |
897 | .DS | |
898 | .ta .5i 2i | |
899 | \fBcfcc | |
900 | \fBsetf | |
901 | \fBsetd | |
902 | \fBseti | |
903 | \fBsetl | |
904 | \fBclrf \fIfdst | |
905 | \fBnegf \fIfdst | |
906 | \fBabsf \fIfdst | |
907 | \fBtstf \fIfsrc | |
908 | \fBmovf \fIfsrc,\|freg \fR(= ldf\fR\|) | |
909 | \fBmovf \fIfreg,\|fdst \fR(= stf\fR\|) | |
910 | \fBmovif \fIsrc,\|freg \fR(= ldcif\fR\|) | |
911 | \fBmovfi \fIfreg,\|dst \fR(= stcfi\fR\|) | |
912 | \fBmovof \fIfsrc,\|freg \fR(= ldcdf\fR\|) | |
913 | \fBmovfo \fIfreg,\|fdst \fR(= stcfd\fR\|) | |
914 | \fBmovie \fIsrc,\|freg \fR(= ldexp\fR) | |
915 | \fBmovei \fIfreg,\|dst \fR(= stexp\fR) | |
916 | \fBaddf \fIfsrc,\|freg | |
917 | \fBsubf \fIfsrc,\|freg | |
918 | \fBmulf \fIfsrc,\|freg | |
919 | \fBdivf \fIfsrc,\|freg | |
920 | \fBcmpf \fIfsrc,\|freg | |
921 | \fBmodf \fIfsrc,\|freg | |
922 | \fBldfps \fIsrc | |
923 | \fBstfps \fIdst | |
924 | \fBstst \fIdst\fR | |
925 | .DE | |
926 | .KE | |
927 | \fIfsrc\fR, \fIfdst\fR, and \fIfreg\fR mean floating-point | |
928 | source, destination, and register respectively. | |
929 | Their syntax is identical to that for | |
930 | their non-floating counterparts, but | |
931 | note that only | |
932 | floating registers 0-3 can be a \fIfreg\fR. | |
933 | .PP | |
934 | The names of several of the operations | |
935 | have been changed to bring out an analogy with | |
936 | certain fixed-point instructions. | |
937 | The only strange case is \fBmovf\fR, which turns into | |
938 | either \fBstf\fR or \fBldf\fR | |
939 | depending respectively on whether its first operand is | |
940 | or is not a register. | |
941 | Warning: \fBldf\fR sets the floating condition codes, | |
942 | \fBstf\fR does not. | |
943 | .SH | |
944 | 9. Other symbols | |
945 | .SH | |
946 | 9.1 \fB.\|.\fR | |
947 | .PP | |
948 | The symbol ``\fB\|.\|.\|\fR'' | |
949 | is the | |
950 | \fIrelocation counter\fR. | |
951 | Just before each assembled word is placed in the output stream, | |
952 | the current value of this symbol is added to the word | |
953 | if the word refers to a text, data or bss segment location. | |
954 | If the output word is a pc-relative address word | |
955 | that refers to an absolute location, | |
956 | the value of ``\fB\|.\|.\|\fR'' is subtracted. | |
957 | .PP | |
958 | Thus the value of ``\fB\|.\|.\|\fR'' can be taken to mean | |
959 | the starting memory location of the program. | |
960 | The initial value of ``\|\fB.\|.\fR\|'' is 0. | |
961 | .PP | |
962 | The value of ``\|\fB.\|.\fR\|'' may be changed by assignment. | |
963 | Such a course of action is sometimes | |
964 | necessary, but the consequences | |
965 | should be carefully thought out. | |
966 | It is particularly ticklish | |
967 | to change ``\|\fB.\|.\fR\|'' midway in an assembly | |
968 | or to do so in a program which will | |
969 | be treated by the loader, which has | |
970 | its own notions of ``\|\fB.\|.\fR\|''. | |
971 | .SH | |
972 | 9.2 System calls | |
973 | .PP | |
974 | System call names are not predefined. | |
975 | They may be found in the file | |
976 | .I /usr/include/sys.s | |
977 | .SH | |
978 | 10. Diagnostics | |
979 | .PP | |
980 | When | |
981 | an input file cannot be read, its name | |
982 | followed by a question mark is typed and assembly | |
983 | ceases. | |
984 | When syntactic or semantic errors occur, a single-character diagnostic is typed out | |
985 | together with the line number and the file name in which it | |
986 | occurred. Errors in pass 1 cause cancellation of pass 2. | |
987 | The possible errors are: | |
988 | .KS | |
989 | .DS | |
990 | .ta .3i | |
991 | ) parentheses error | |
992 | ] parentheses error | |
993 | > string not terminated properly | |
994 | * indirection (\|*\|) used illegally | |
995 | \&\fB.\fR illegal assignment to ``\|\fB.\fR\|'' | |
996 | \s8A\s10 error in address | |
997 | \s8B\s10 branch address is odd or too remote | |
998 | \s8E\s10 error in expression | |
999 | \s8F\s10 error in local (``f\|'' or ``b'') type symbol | |
1000 | \s8G\s10 garbage (unknown) character | |
1001 | \s8I\s10 end of file inside an \fB.if\fR | |
1002 | \s8M\s10 multiply defined symbol as label | |
1003 | \s8O\s10 word quantity assembled at odd address | |
1004 | \s8P\s10 phase error\(em ``\|\fB.\fP\|'' different in pass 1 and 2 | |
1005 | \s8R\s10 relocation error | |
1006 | \s8U\s10 undefined symbol | |
1007 | \s8X\s10 syntax error | |
1008 | .DE | |
1009 | .KE |