4.1cBSD/usr/doc/as/asdocs2.me

Compare this file to the similar file:
Show the results in this format:

.\"
.\"	Copyright (c) 1982 Regents of the University of California
.\"	@(#)asdocs2.me 1.6 2/11/83
.\"
.EQ
delim $$
.EN
.SH 1 "Statements"
.pp
A source program is composed of a sequence of
.i statements .
Statements are separated either by new-lines
or by semicolons.
There are two kinds of statements: null statements
and keyword statements.
Either kind of statement may be preceded by
one or more labels.
.SH 2 "Named Global Labels"
.pp
A global label consists of a name followed
by a colon.
The effect of a name label is to assign the current
value and type of the location counter
to the name.
An error is indicated in pass 1 if the
name is already defined;
an error is indicated in pass 2 if the
value assigned changes the definition
of the label.
.pp
A global label is referenced by its name.
.pp
Global labels beginning with a
.q "\|L\|"
are discarded unless the
.b \-L
option
is in effect.
.SH 2 "Numeric Local Labels"
.pp
A numeric label consists of a digit  $0$ to $9$
followed by a colon.
Such a label serves to define temporary symbols of the form
.q "$n roman b$"
and
.q "$n roman f$" ,
where $n$
is the digit of the label.
As in the case of name labels,
a numeric label assigns
the current value and type of the location counter
to the temporary symbol.
However, several numeric labels with the same digit
may be used within the same assembly.
References to symbols of the form
.q "$n roman b$"
refer to the first numeric label
.q "$n$:"
.i b ackwards
from the reference;
.q "$n roman f$"
symbols refer to the first numeric label
.q "$n$:"
.i f orwards
from the reference.
Such numeric labels conserve the inventive powers
of the human programmer.
.pp
For various reasons,
.i as
turns local labels into labels of the form
$roman L n roman ".\*(DL" m$.
Although unlikely,
these generated labels may conflict
with programmer defined labels.
.SH 2 "Null statements"
.pp
A null statement is an empty statement ignored by the assembler.
A null statement may be labeled, however.
.SH 2 "Keyword statements"
.pp
A keyword statement begins with one of the many predefined
keywords known to
.i as ;
the syntax of the remainder of the statement depends
on the keyword.
All instruction opcodes are keywords.
The remaining keywords are assembler pseudo-operations,
also called
.i directives .
The pseudo-operations are listed in \(sc8,
together with the syntax they require.
.SH 1 "Expressions"
.pp
An expression is a sequence of symbols representing a value.
Its constituents are identifiers,
constants,
operators,
and parentheses.
Each expression has a type.
.pp
All operators in expressions are fundamentally binary in
nature.
Arithmetic is two's complement and has 32 bits of precision.
.i As
can not do arithmetic on floating point numbers, quad or octal
precision scalar numbers.
There are four levels of precedence,
listed here from
lowest precedence level to highest:
.(b
.TS
center;
c l.
precedence	operators
_
binary	$+$, $-$
binary	\fI\(bv\fP\|, $&$, $italic "^"$, $!$
binary	$*$, $/$, $%$,
unary	$-$, $italic "~"$
.TE
.)b
.pp
All operators of the same precedence are evaluated strictly left to right,
except for the evaluation order enforced by parenthesis.
.SH 2 "Expression Operators"
.pp
The operators are:
.(b
.TS
center;
c l.
operator	meaning
_
$+$	addition
$-$	(binary) subtraction
$*$	multiplication
$/$	division
$%$	modulo
$-$	(unary) 2's complement
$&$	bitwise and
$\(bv$	bitwise or
$italic "^"$	bitwise exclusive or
$!$	bitwise or not
$italic "~"$	bitwise 1's complement
$>$	logical right shift
$>>$	logical right shift
$<$	logical left shift
$<<$	logical left shift
.TE
.)b
.pp
Expressions may be grouped by use of parentheses,
.q "("
and
.q ")".
.SH 2 "Data Types"
.pp
The assembler manipulates several different
types of expressions.
The types likely to be met explicitly are:
.nr ii \w'undefined\ \ 'u
.ip "undefined" 
Upon first encounter,
each symbol is undefined.
It may become undefined if it is assigned an undefined expression.
It is an error to attempt to assemble an undefined
expression in pass 2;
in pass 1,
it is not (except that
certain keywords require operands which are not undefined).
.ip "undefined\ external" 
A symbol which is declared
.b .globl
but not defined
in the current assembly is an undefined external.
If such a symbol is declared,
the link editor
.i ld
must be used to load the assembler's output with
another routine that defines the undefined reference.
.ip "absolute"
An absolute symbol is defined ultimately from a constant.
Its value is unaffected by any possible future applications
of the link-editor to the output file.
.ip "text"
The value of a text symbol is measured
with respect to the beginning of the text segment of the program.
If the assembler output is link-edited,
its text symbols may change in value
since the program need
not be the first in the link editor's output.
Most text symbols are defined by appearing as labels.
At the start of an assembly,
the value of
.q "\|\fB.\fP\|"
is
.q "text 0" .
.ip "data"
The value of a data symbol is measured
with respect to the origin of the data segment of a program.
Like text symbols,
the value of a data symbol may change
during a subsequent link-editor run since previously
loaded programs may have data segments.
After the first
.b .data
statement,
the value of
.q "\|\fB.\fP\|"
is
.q "data 0".
.ip "bss"
The value of a bss symbol is measured from
the beginning of the bss segment of a program.
Like text and data symbols,
the value of a bss symbol
may change during a subsequent link-editor run,
since previously loaded programs may have bss segments.
.ip "external\ absolute,\ text,\ data,\ or\ bss" 
Symbols declared
.b .globl
but defined within an assembly as absolute,
text,
data,
or bss
symbols may be used exactly as if they were not
declared
.b .globl ;
however, their value and type are available
to the link editor so that the program may be loaded with others
that reference these symbols.
.ip "register"
The symbols
.(q
.b "r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15"
.b "ap fp sp pc"
.)q
are predefined
as register symbols.
In addition, the 
.q "%"
operator converts the following absolute expression whose
value is between 0 and 15 into a register reference.
.ip "other\ types\ \ " 
Each keyword known to the assembler has a type which
is used to select the routine which processes
the associated keyword statement.
The behavior of such symbols
when not used as keywords is the same as if they were absolute.
.SH 2 "Type Propagation in Expressions"
.pp
When operands are combined by expression operators,
the result has a type which depends on the types
of the operands and on the operator.
The rules involved are complex to state but
were intended to be sensible and predictable.
For purposes of expression evaluation the
important types are
.(b
.TS
center;
l.
undefined
absolute
text
data
bss
undefined external
other
.TE
.)b
.pp
The combination rules are then
.nr ii 5n
.np
If one of the operands is undefined,
the result is undefined.
.np
If both operands are absolute,
the result is absolute.
.np
If an absolute is combined with one of the
.q "other types"
mentioned above,
the result has the other type.
An
.q "other type"
combined with an explicitly
discussed type other than absolute
it acts like an absolute.
.pp
Further rules applying to particular operators are:
.ip "$+$"
If one operand is text-, data-, or bss-segment
relocatable, or is an undefined external,
the result has the postulated type and the other operand
must be absolute.
.ip $-$
If the first operand is a relocatable
text-, data-, or bss-segment symbol, the second operand
may be absolute (in which case the result has the
type of the first operand);
or the second operand may have the same type
as the first (in which case the result is absolute).
If the first operand is external undefined,
the second must be absolute.
All other combinations are illegal.
.ip others
It is illegal to apply these operators to any but absolute symbols.