246 lines
5.8 KiB
HTML
246 lines
5.8 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<!-- This HTML file has been created by texi2html 1.52
|
|
from ../texi/as.texinfo on 24 April 1999 -->
|
|
|
|
<TITLE>Using as - Expressions</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
Go to the <A HREF="as_1.html">first</A>, <A HREF="as_5.html">previous</A>, <A HREF="as_7.html">next</A>, <A HREF="as_27.html">last</A> section, <A HREF="as_toc.html">table of contents</A>.
|
|
<P><HR><P>
|
|
|
|
|
|
<H1><A NAME="SEC60" HREF="as_toc.html#TOC60">Expressions</A></H1>
|
|
|
|
<P>
|
|
<A NAME="IDX221"></A>
|
|
<A NAME="IDX222"></A>
|
|
<A NAME="IDX223"></A>
|
|
An <EM>expression</EM> specifies an address or numeric value.
|
|
Whitespace may precede and/or follow an expression.
|
|
|
|
</P>
|
|
<P>
|
|
The result of an expression must be an absolute number, or else an offset into
|
|
a particular section. If an expression is not absolute, and there is not
|
|
enough information when <CODE>as</CODE> sees the expression to know its
|
|
section, a second pass over the source program might be necessary to interpret
|
|
the expression--but the second pass is currently not implemented.
|
|
<CODE>as</CODE> aborts with an error message in this situation.
|
|
|
|
</P>
|
|
|
|
|
|
|
|
<H2><A NAME="SEC61" HREF="as_toc.html#TOC61">Empty Expressions</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX224"></A>
|
|
<A NAME="IDX225"></A>
|
|
An empty expression has no value: it is just whitespace or null.
|
|
Wherever an absolute expression is required, you may omit the
|
|
expression, and <CODE>as</CODE> assumes a value of (absolute) 0. This
|
|
is compatible with other assemblers.
|
|
|
|
</P>
|
|
|
|
|
|
<H2><A NAME="SEC62" HREF="as_toc.html#TOC62">Integer Expressions</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX226"></A>
|
|
<A NAME="IDX227"></A>
|
|
An <EM>integer expression</EM> is one or more <EM>arguments</EM> delimited
|
|
by <EM>operators</EM>.
|
|
|
|
</P>
|
|
|
|
|
|
|
|
<H3><A NAME="SEC63" HREF="as_toc.html#TOC63">Arguments</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX228"></A>
|
|
<A NAME="IDX229"></A>
|
|
<A NAME="IDX230"></A>
|
|
<A NAME="IDX231"></A>
|
|
<EM>Arguments</EM> are symbols, numbers or subexpressions. In other
|
|
contexts arguments are sometimes called "arithmetic operands". In
|
|
this manual, to avoid confusing them with the "instruction operands" of
|
|
the machine language, we use the term "argument" to refer to parts of
|
|
expressions only, reserving the word "operand" to refer only to machine
|
|
instruction operands.
|
|
|
|
</P>
|
|
<P>
|
|
Symbols are evaluated to yield {<VAR>section</VAR> <VAR>NNN</VAR>} where
|
|
<VAR>section</VAR> is one of text, data, bss, absolute,
|
|
or undefined. <VAR>NNN</VAR> is a signed, 2's complement 32 bit
|
|
integer.
|
|
|
|
</P>
|
|
<P>
|
|
Numbers are usually integers.
|
|
|
|
</P>
|
|
<P>
|
|
A number can be a flonum or bignum. In this case, you are warned
|
|
that only the low order 32 bits are used, and <CODE>as</CODE> pretends
|
|
these 32 bits are an integer. You may write integer-manipulating
|
|
instructions that act on exotic constants, compatible with other
|
|
assemblers.
|
|
|
|
</P>
|
|
<P>
|
|
<A NAME="IDX232"></A>
|
|
Subexpressions are a left parenthesis <SAMP>`('</SAMP> followed by an integer
|
|
expression, followed by a right parenthesis <SAMP>`)'</SAMP>; or a prefix
|
|
operator followed by an argument.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC64" HREF="as_toc.html#TOC64">Operators</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX233"></A>
|
|
<A NAME="IDX234"></A>
|
|
<A NAME="IDX235"></A>
|
|
<EM>Operators</EM> are arithmetic functions, like <CODE>+</CODE> or <CODE>%</CODE>. Prefix
|
|
operators are followed by an argument. Infix operators appear
|
|
between their arguments. Operators may be preceded and/or followed by
|
|
whitespace.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC65" HREF="as_toc.html#TOC65">Prefix Operator</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX236"></A>
|
|
<CODE>as</CODE> has the following <EM>prefix operators</EM>. They each take
|
|
one argument, which must be absolute.
|
|
|
|
</P>
|
|
|
|
<DL COMPACT>
|
|
|
|
<DT><CODE>-</CODE>
|
|
<DD>
|
|
<EM>Negation</EM>. Two's complement negation.
|
|
<DT><CODE>~</CODE>
|
|
<DD>
|
|
<EM>Complementation</EM>. Bitwise not.
|
|
</DL>
|
|
|
|
|
|
|
|
<H3><A NAME="SEC66" HREF="as_toc.html#TOC66">Infix Operators</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX237"></A>
|
|
<A NAME="IDX238"></A>
|
|
<EM>Infix operators</EM> take two arguments, one on either side. Operators
|
|
have precedence, but operations with equal precedence are performed left
|
|
to right. Apart from <CODE>+</CODE> or <CODE>-</CODE>, both arguments must be
|
|
absolute, and the result is absolute.
|
|
|
|
</P>
|
|
|
|
<OL>
|
|
|
|
<LI>
|
|
|
|
<A NAME="IDX239"></A>
|
|
<A NAME="IDX240"></A>
|
|
|
|
Highest Precedence
|
|
|
|
<DL COMPACT>
|
|
|
|
<DT><CODE>*</CODE>
|
|
<DD>
|
|
<EM>Multiplication</EM>.
|
|
|
|
<DT><CODE>/</CODE>
|
|
<DD>
|
|
<EM>Division</EM>. Truncation is the same as the C operator <SAMP>`/'</SAMP>
|
|
|
|
<DT><CODE>%</CODE>
|
|
<DD>
|
|
<EM>Remainder</EM>.
|
|
|
|
<DT><CODE><</CODE>
|
|
<DD>
|
|
<DT><CODE><<</CODE>
|
|
<DD>
|
|
<EM>Shift Left</EM>. Same as the C operator <SAMP>`<<'</SAMP>.
|
|
|
|
<DT><CODE>></CODE>
|
|
<DD>
|
|
<DT><CODE>>></CODE>
|
|
<DD>
|
|
<EM>Shift Right</EM>. Same as the C operator <SAMP>`>>'</SAMP>.
|
|
</DL>
|
|
|
|
<LI>
|
|
|
|
Intermediate precedence
|
|
|
|
<DL COMPACT>
|
|
|
|
<DT><CODE>|</CODE>
|
|
<DD>
|
|
<EM>Bitwise Inclusive Or</EM>.
|
|
|
|
<DT><CODE>&</CODE>
|
|
<DD>
|
|
<EM>Bitwise And</EM>.
|
|
|
|
<DT><CODE>^</CODE>
|
|
<DD>
|
|
<EM>Bitwise Exclusive Or</EM>.
|
|
|
|
<DT><CODE>!</CODE>
|
|
<DD>
|
|
<EM>Bitwise Or Not</EM>.
|
|
</DL>
|
|
|
|
<LI>
|
|
|
|
Lowest Precedence
|
|
|
|
<DL COMPACT>
|
|
|
|
<DT><CODE>+</CODE>
|
|
<DD>
|
|
<A NAME="IDX241"></A>
|
|
<A NAME="IDX242"></A>
|
|
<A NAME="IDX243"></A>
|
|
|
|
<EM>Addition</EM>. If either argument is absolute, the result has the section of
|
|
the other argument. You may not add together arguments from different
|
|
sections.
|
|
|
|
<A NAME="IDX244"></A>
|
|
<A NAME="IDX245"></A>
|
|
<A NAME="IDX246"></A>
|
|
<DT><CODE>-</CODE>
|
|
<DD>
|
|
<EM>Subtraction</EM>. If the right argument is absolute, the
|
|
result has the section of the left argument.
|
|
If both arguments are in the same section, the result is absolute.
|
|
You may not subtract arguments from different sections.
|
|
</DL>
|
|
</OL>
|
|
|
|
<P>
|
|
In short, it's only meaningful to add or subtract the <EM>offsets</EM> in an
|
|
address; you can only have a defined section in one of the two arguments.
|
|
|
|
</P>
|
|
<P><HR><P>
|
|
Go to the <A HREF="as_1.html">first</A>, <A HREF="as_5.html">previous</A>, <A HREF="as_7.html">next</A>, <A HREF="as_27.html">last</A> section, <A HREF="as_toc.html">table of contents</A>.
|
|
</BODY>
|
|
</HTML>
|