[Main]
Title=Sub-Sections

[Top]
You may have separate groups of
data in named sections
that you want to end up near to each other in the object file, even though they
are not contiguous in the assembler source.  <CODE>as</CODE> allows you to
use <U>subsections</U> for this purpose.  Within each section, there can be
numbered subsections with values from 0 to 8192.  Objects assembled into the
same subsection go into the object file together with other objects in the same
subsection.  For example, a compiler might want to store constants in the text
section, but might not want to have them interspersed with the program being
assembled.  In this case, the compiler could issue a <CODE>.text&nbsp;0</CODE> before each
section of code being output, and a <CODE>.text&nbsp;1</CODE> before each group of
constants being output.
<BR><BR>
Subsections are optional.  If you do not use subsections, everything
goes in subsection number zero.
<BR><BR>
Subsections appear in your object file in numeric order, lowest numbered
to highest.  (All this to be compatible with other people's assemblers.)
The object file contains no representation of subsections; <CODE>ld</CODE> and
other programs that manipulate object files see no trace of them.
They just see all your text subsections as a text section, and all your
data subsections as a data section.
<BR><BR>
To specify which subsection you want subsequent statements assembled
into, use a numeric argument to specify it, in a <CODE>.text
<I>expression</I></CODE> or a <CODE>.data <I>expression</I></CODE> statement.
You
can also use an extra subsection
argument with arbitrarily named sections: <CODE>.section <I>name</I>,
<I>expression</I></CODE>.
<I>Expression</I> should be an absolute expression.
(see <A HREF="$$LINK(SEC60)">Expressions</A>.)  If you just say <CODE>.text</CODE> then <CODE>.text&nbsp;0</CODE>
is assumed.  Likewise <CODE>.data</CODE> means <CODE>.data&nbsp;0</CODE>.  Assembly
begins in <CODE>text&nbsp;0</CODE>.  For instance:
<PRE>.text 0     # The default subsection is text 0 anyway.
.ascii &quot;This lives in the first text subsection. *&quot;
.text 1
.ascii &quot;But this lives in the second text subsection.&quot;
.data 0
.ascii &quot;This lives in the data section,&quot;
.ascii &quot;in the first data subsection.&quot;
.text 0
.ascii &quot;This lives in the first text section,&quot;
.ascii &quot;immediately following the asterisk (*).&quot;
</PRE>
Each section has a <U>location counter</U> incremented by one for every byte
assembled into that section.  Because subsections are merely a convenience
restricted to <CODE>as</CODE> there is no concept of a subsection location
counter.  There is no way to directly manipulate a location counter - but the
<CODE><A HREF="$$LINK(SEC70)">.align</A></CODE> directive changes it, and any label definition captures its
current value.  The location counter of the section where statements are being
assembled is said to be the <U>active</U> location counter.
