334 lines
10 KiB
HTML
334 lines
10 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 - Symbols</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
Go to the <A HREF="as_1.html">first</A>, <A HREF="as_4.html">previous</A>, <A HREF="as_6.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="SEC45" HREF="as_toc.html#TOC45">Symbols</A></H1>
|
|
|
|
<P>
|
|
<A NAME="IDX190"></A>
|
|
Symbols are a central concept: the programmer uses symbols to name
|
|
things, the linker uses symbols to link, and the debugger uses symbols
|
|
to debug.
|
|
|
|
</P>
|
|
|
|
<BLOCKQUOTE>
|
|
<A NAME="IDX191"></A>
|
|
<P>
|
|
<EM>Warning:</EM> <CODE>as</CODE> does not place symbols in the object file in
|
|
the same order they were declared. This may break some debuggers.
|
|
</BLOCKQUOTE>
|
|
|
|
|
|
|
|
<H2><A NAME="SEC46" HREF="as_toc.html#TOC46">Labels</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX192"></A>
|
|
A <EM>label</EM> is written as a symbol immediately followed by a colon
|
|
<SAMP>`:'</SAMP>. The symbol then represents the current value of the
|
|
active location counter, and is, for example, a suitable instruction
|
|
operand. You are warned if you use the same symbol to represent two
|
|
different locations: the first definition overrides any other
|
|
definitions.
|
|
|
|
</P>
|
|
<P>
|
|
On the HPPA, the usual form for a label need not be immediately followed by a
|
|
colon, but instead must start in column zero. Only one label may be defined on
|
|
a single line. To work around this, the HPPA version of <CODE>as</CODE> also
|
|
provides a special directive <CODE>.label</CODE> for defining labels more flexibly.
|
|
|
|
</P>
|
|
|
|
|
|
<H2><A NAME="SEC47" HREF="as_toc.html#TOC47">Giving Symbols Other Values</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX193"></A>
|
|
<A NAME="IDX194"></A>
|
|
A symbol can be given an arbitrary value by writing a symbol, followed
|
|
by an equals sign <SAMP>`='</SAMP>, followed by an expression
|
|
(see section <A HREF="as_6.html#SEC60">Expressions</A>). This is equivalent to using the <CODE>.set</CODE>
|
|
directive. See section <A HREF="as_7.html#SEC120"><CODE>.set <VAR>symbol</CODE>, <VAR>expression</VAR></VAR></A>.
|
|
|
|
</P>
|
|
|
|
|
|
<H2><A NAME="SEC48" HREF="as_toc.html#TOC48">Symbol Names</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX195"></A>
|
|
<A NAME="IDX196"></A>
|
|
Symbol names begin with a letter or with one of <SAMP>`._'</SAMP>. On most
|
|
machines, you can also use <CODE>$</CODE> in symbol names; exceptions are
|
|
noted in section <A HREF="as_8.html#SEC138">Machine Dependent Features</A>. That character may be followed by any
|
|
string of digits, letters, dollar signs (unless otherwise noted in
|
|
section <A HREF="as_8.html#SEC138">Machine Dependent Features</A>), and underscores.
|
|
For the AMD 29K family, <SAMP>`?'</SAMP> is also allowed in the
|
|
body of a symbol name, though not at its beginning.
|
|
|
|
</P>
|
|
|
|
<P>
|
|
Case of letters is significant: <CODE>foo</CODE> is a different symbol name
|
|
than <CODE>Foo</CODE>.
|
|
|
|
</P>
|
|
<P>
|
|
Each symbol has exactly one name. Each name in an assembly language program
|
|
refers to exactly one symbol. You may use that symbol name any number of times
|
|
in a program.
|
|
|
|
</P>
|
|
|
|
<H3>Local Symbol Names</H3>
|
|
|
|
<P>
|
|
<A NAME="IDX197"></A>
|
|
<A NAME="IDX198"></A>
|
|
<A NAME="IDX199"></A>
|
|
<A NAME="IDX200"></A>
|
|
Local symbols help compilers and programmers use names temporarily.
|
|
There are ten local symbol names, which are re-used throughout the
|
|
program. You may refer to them using the names <SAMP>`0'</SAMP> <SAMP>`1'</SAMP>
|
|
... <SAMP>`9'</SAMP>. To define a local symbol, write a label of the form
|
|
<SAMP>`<B>N</B>:'</SAMP> (where <B>N</B> represents any digit). To refer to the most
|
|
recent previous definition of that symbol write <SAMP>`<B>N</B>b'</SAMP>, using the
|
|
same digit as when you defined the label. To refer to the next
|
|
definition of a local label, write <SAMP>`<B>N</B>f'</SAMP>---where <B>N</B> gives you
|
|
a choice of 10 forward references. The <SAMP>`b'</SAMP> stands for
|
|
"backwards" and the <SAMP>`f'</SAMP> stands for "forwards".
|
|
|
|
</P>
|
|
<P>
|
|
Local symbols are not emitted by the current GNU C compiler.
|
|
|
|
</P>
|
|
<P>
|
|
There is no restriction on how you can use these labels, but
|
|
remember that at any point in the assembly you can refer to at most
|
|
10 prior local labels and to at most 10 forward local labels.
|
|
|
|
</P>
|
|
<P>
|
|
Local symbol names are only a notation device. They are immediately
|
|
transformed into more conventional symbol names before the assembler
|
|
uses them. The symbol names stored in the symbol table, appearing in
|
|
error messages and optionally emitted to the object file have these
|
|
parts:
|
|
|
|
</P>
|
|
<DL COMPACT>
|
|
|
|
<DT><CODE>L</CODE>
|
|
<DD>
|
|
All local labels begin with <SAMP>`L'</SAMP>. Normally both <CODE>as</CODE> and
|
|
<CODE>ld</CODE> forget symbols that start with <SAMP>`L'</SAMP>. These labels are
|
|
used for symbols you are never intended to see. If you use the
|
|
<SAMP>`-L'</SAMP> option then <CODE>as</CODE> retains these symbols in the
|
|
object file. If you also instruct <CODE>ld</CODE> to retain these symbols,
|
|
you may use them in debugging.
|
|
|
|
<DT><CODE><VAR>digit</VAR></CODE>
|
|
<DD>
|
|
If the label is written <SAMP>`0:'</SAMP> then the digit is <SAMP>`0'</SAMP>.
|
|
If the label is written <SAMP>`1:'</SAMP> then the digit is <SAMP>`1'</SAMP>.
|
|
And so on up through <SAMP>`9:'</SAMP>.
|
|
|
|
<DT><CODE><KBD>C-A</KBD></CODE>
|
|
<DD>
|
|
This unusual character is included so you do not accidentally invent
|
|
a symbol of the same name. The character has ASCII value
|
|
<SAMP>`\001'</SAMP>.
|
|
|
|
<DT><CODE><EM>ordinal number</EM></CODE>
|
|
<DD>
|
|
This is a serial number to keep the labels distinct. The first
|
|
<SAMP>`0:'</SAMP> gets the number <SAMP>`1'</SAMP>; The 15th <SAMP>`0:'</SAMP> gets the
|
|
number <SAMP>`15'</SAMP>; <EM>etc.</EM>. Likewise for the other labels <SAMP>`1:'</SAMP>
|
|
through <SAMP>`9:'</SAMP>.
|
|
</DL>
|
|
|
|
<P>
|
|
For instance, the first <CODE>1:</CODE> is named <CODE>L1<KBD>C-A</KBD>1</CODE>, the 44th
|
|
<CODE>3:</CODE> is named <CODE>L3<KBD>C-A</KBD>44</CODE>.
|
|
|
|
</P>
|
|
|
|
|
|
<H2><A NAME="SEC49" HREF="as_toc.html#TOC49">The Special Dot Symbol</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX201"></A>
|
|
<A NAME="IDX202"></A>
|
|
<A NAME="IDX203"></A>
|
|
<A NAME="IDX204"></A>
|
|
The special symbol <SAMP>`.'</SAMP> refers to the current address that
|
|
<CODE>as</CODE> is assembling into. Thus, the expression <SAMP>`melvin:
|
|
.long .'</SAMP> defines <CODE>melvin</CODE> to contain its own address.
|
|
Assigning a value to <CODE>.</CODE> is treated the same as a <CODE>.org</CODE>
|
|
directive. Thus, the expression <SAMP>`.=.+4'</SAMP> is the same as saying
|
|
<SAMP>`.space 4'</SAMP>.
|
|
|
|
</P>
|
|
|
|
|
|
<H2><A NAME="SEC50" HREF="as_toc.html#TOC50">Symbol Attributes</A></H2>
|
|
|
|
<P>
|
|
<A NAME="IDX205"></A>
|
|
<A NAME="IDX206"></A>
|
|
Every symbol has, as well as its name, the attributes "Value" and
|
|
"Type". Depending on output format, symbols can also have auxiliary
|
|
attributes.
|
|
|
|
</P>
|
|
<P>
|
|
If you use a symbol without defining it, <CODE>as</CODE> assumes zero for
|
|
all these attributes, and probably won't warn you. This makes the
|
|
symbol an externally defined symbol, which is generally what you
|
|
would want.
|
|
|
|
</P>
|
|
|
|
|
|
|
|
<H3><A NAME="SEC51" HREF="as_toc.html#TOC51">Value</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX207"></A>
|
|
<A NAME="IDX208"></A>
|
|
The value of a symbol is (usually) 32 bits. For a symbol which labels a
|
|
location in the text, data, bss or absolute sections the value is the
|
|
number of addresses from the start of that section to the label.
|
|
Naturally for text, data and bss sections the value of a symbol changes
|
|
as <CODE>ld</CODE> changes section base addresses during linking. Absolute
|
|
symbols' values do not change during linking: that is why they are
|
|
called absolute.
|
|
|
|
</P>
|
|
<P>
|
|
The value of an undefined symbol is treated in a special way. If it is
|
|
0 then the symbol is not defined in this assembler source file, and
|
|
<CODE>ld</CODE> tries to determine its value from other files linked into the
|
|
same program. You make this kind of symbol simply by mentioning a symbol
|
|
name without defining it. A non-zero value represents a <CODE>.comm</CODE>
|
|
common declaration. The value is how much common storage to reserve, in
|
|
bytes (addresses). The symbol refers to the first address of the
|
|
allocated storage.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC52" HREF="as_toc.html#TOC52">Type</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX209"></A>
|
|
<A NAME="IDX210"></A>
|
|
The type attribute of a symbol contains relocation (section)
|
|
information, any flag settings indicating that a symbol is external, and
|
|
(optionally), other information for linkers and debuggers. The exact
|
|
format depends on the object-code output format in use.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC53" HREF="as_toc.html#TOC53">Symbol Attributes: <CODE>a.out</CODE></A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX211"></A>
|
|
<A NAME="IDX212"></A>
|
|
|
|
</P>
|
|
|
|
|
|
|
|
<H4><A NAME="SEC54" HREF="as_toc.html#TOC54">Descriptor</A></H4>
|
|
|
|
<P>
|
|
<A NAME="IDX213"></A>
|
|
This is an arbitrary 16-bit value. You may establish a symbol's
|
|
descriptor value by using a <CODE>.desc</CODE> statement
|
|
(see section <A HREF="as_7.html#SEC79"><CODE>.desc <VAR>symbol</CODE>, <VAR>abs-expression</VAR></VAR></A>). A descriptor value means nothing to
|
|
<CODE>as</CODE>.
|
|
|
|
</P>
|
|
|
|
|
|
<H4><A NAME="SEC55" HREF="as_toc.html#TOC55">Other</A></H4>
|
|
|
|
<P>
|
|
<A NAME="IDX214"></A>
|
|
This is an arbitrary 8-bit value. It means nothing to <CODE>as</CODE>.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC56" HREF="as_toc.html#TOC56">Symbol Attributes for COFF</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX215"></A>
|
|
<A NAME="IDX216"></A>
|
|
|
|
</P>
|
|
<P>
|
|
The COFF format supports a multitude of auxiliary symbol attributes;
|
|
like the primary symbol attributes, they are set between <CODE>.def</CODE> and
|
|
<CODE>.endef</CODE> directives.
|
|
|
|
</P>
|
|
|
|
|
|
<H4><A NAME="SEC57" HREF="as_toc.html#TOC57">Primary Attributes</A></H4>
|
|
|
|
<P>
|
|
<A NAME="IDX217"></A>
|
|
The symbol name is set with <CODE>.def</CODE>; the value and type,
|
|
respectively, with <CODE>.val</CODE> and <CODE>.type</CODE>.
|
|
|
|
</P>
|
|
|
|
|
|
<H4><A NAME="SEC58" HREF="as_toc.html#TOC58">Auxiliary Attributes</A></H4>
|
|
|
|
<P>
|
|
<A NAME="IDX218"></A>
|
|
The <CODE>as</CODE> directives <CODE>.dim</CODE>, <CODE>.line</CODE>, <CODE>.scl</CODE>,
|
|
<CODE>.size</CODE>, and <CODE>.tag</CODE> can generate auxiliary symbol table
|
|
information for COFF.
|
|
|
|
</P>
|
|
|
|
|
|
<H3><A NAME="SEC59" HREF="as_toc.html#TOC59">Symbol Attributes for SOM</A></H3>
|
|
|
|
<P>
|
|
<A NAME="IDX219"></A>
|
|
<A NAME="IDX220"></A>
|
|
|
|
</P>
|
|
<P>
|
|
The SOM format for the HPPA supports a multitude of symbol attributes set with
|
|
the <CODE>.EXPORT</CODE> and <CODE>.IMPORT</CODE> directives.
|
|
|
|
</P>
|
|
<P>
|
|
The attributes are described in <CITE>HP9000 Series 800 Assembly
|
|
Language Reference Manual</CITE> (HP 92432-90001) under the <CODE>IMPORT</CODE> and
|
|
<CODE>EXPORT</CODE> assembler directive documentation.
|
|
|
|
</P>
|
|
<P><HR><P>
|
|
Go to the <A HREF="as_1.html">first</A>, <A HREF="as_4.html">previous</A>, <A HREF="as_6.html">next</A>, <A HREF="as_27.html">last</A> section, <A HREF="as_toc.html">table of contents</A>.
|
|
</BODY>
|
|
</HTML>
|