blob: bfcbbb2e8d331b08c5a0164241c50fe863a6d7eb [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the GNU Assembler "as".
Copyright (C) 1991-2013 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the
section entitled "GNU Free Documentation License".
-->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Using as: Sub-Sections</title>
<meta name="description" content="Using as: Sub-Sections">
<meta name="keywords" content="Using as: Sub-Sections">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Sections.html#Sections" rel="up" title="Sections">
<link href="bss.html#bss" rel="next" title="bss">
<link href="As-Sections.html#As-Sections" rel="prev" title="As Sections">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Sub_002dSections"></a>
<div class="header">
<p>
Next: <a href="bss.html#bss" accesskey="n" rel="next">bss</a>, Previous: <a href="As-Sections.html#As-Sections" accesskey="p" rel="prev">As Sections</a>, Up: <a href="Sections.html#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Sub_002dSections-1"></a>
<h3 class="section">4.4 Sub-Sections</h3>
<a name="index-numbered-subsections"></a>
<a name="index-grouping-data"></a>
<p>Assembled bytes
conventionally
fall into two sections: text and data.
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 <em>subsections</em> 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 &lsquo;<samp>.text 0</samp>&rsquo; before each
section of code being output, and a &lsquo;<samp>.text 1</samp>&rsquo; before each group of
constants being output.
</p>
<p>Subsections are optional. If you do not use subsections, everything
goes in subsection number zero.
</p>
<p>Each subsection is zero-padded up to a multiple of four bytes.
(Subsections may be padded a different amount on different flavors
of <code>as</code>.)
</p>
<p>Subsections appear in your object file in numeric order, lowest numbered
to highest. (All this to be compatible with other people&rsquo;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.
</p>
<p>To specify which subsection you want subsequent statements assembled
into, use a numeric argument to specify it, in a &lsquo;<samp>.text
<var>expression</var></samp>&rsquo; or a &lsquo;<samp>.data <var>expression</var></samp>&rsquo; statement.
When generating COFF output, you
can also use an extra subsection
argument with arbitrary named sections: &lsquo;<samp>.section <var>name</var>,
<var>expression</var></samp>&rsquo;.
When generating ELF output, you
can also use the <code>.subsection</code> directive (see <a href="SubSection.html#SubSection">SubSection</a>)
to specify a subsection: &lsquo;<samp>.subsection <var>expression</var></samp>&rsquo;.
<var>Expression</var> should be an absolute expression
(see <a href="Expressions.html#Expressions">Expressions</a>). If you just say &lsquo;<samp>.text</samp>&rsquo; then &lsquo;<samp>.text 0</samp>&rsquo;
is assumed. Likewise &lsquo;<samp>.data</samp>&rsquo; means &lsquo;<samp>.data 0</samp>&rsquo;. Assembly
begins in <code>text 0</code>. For instance:
</p><div class="smallexample">
<pre class="smallexample">.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></div>
<p>Each section has a <em>location counter</em> 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&mdash;but the
<code>.align</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 <em>active</em> location counter.
</p>
<hr>
<div class="header">
<p>
Next: <a href="bss.html#bss" accesskey="n" rel="next">bss</a>, Previous: <a href="As-Sections.html#As-Sections" accesskey="p" rel="prev">As Sections</a>, Up: <a href="Sections.html#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>