home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / as / as
Encoding:
Text File  |  1975-06-26  |  30.4 KB  |  1,155 lines

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