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