<html lang="en"> <head> <title>Sub-Sections - Using as</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Using as"> <meta name="generator" content="makeinfo 4.7"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Sections.html#Sections" title="Sections"> <link rel="prev" href="As-Sections.html#As-Sections" title="As Sections"> <link rel="next" href="bss.html#bss" title="bss"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- This file documents the GNU Assembler "as". Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002, 2006, 2007 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.1 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''. man end--> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family: serif; font-weight: normal; } --></style> </head> <body> <div class="node"> <p> <a name="Sub_002dSections"></a>Next: <a rel="next" accesskey="n" href="bss.html#bss">bss</a>, Previous: <a rel="previous" accesskey="p" href="As-Sections.html#As-Sections">As Sections</a>, Up: <a rel="up" accesskey="u" href="Sections.html#Sections">Sections</a> <hr><br> </div> <h3 class="section">4.4 Sub-Sections</h3> <p><a name="index-numbered-subsections-204"></a><a name="index-grouping-data-205"></a>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. <span class="command">as</span> allows you to use <dfn>subsections</dfn> 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 <span class="samp">.text 0</span> before each section of code being output, and a <span class="samp">.text 1</span> before each group of constants being output. <p>Subsections are optional. If you do not use subsections, everything goes in subsection number zero. <p>Each subsection is zero-padded up to a multiple of four bytes. (Subsections may be padded a different amount on different flavors of <span class="command">as</span>.) <p>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. <p>To specify which subsection you want subsequent statements assembled into, use a numeric argument to specify it, in a <span class="samp">.text </span><var>expression</var> or a <span class="samp">.data </span><var>expression</var> statement. When generating COFF output, you can also use an extra subsection argument with arbitrary named sections: <span class="samp">.section </span><var>name</var><span class="samp">, </span><var>expression</var>. 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: <span class="samp">.subsection </span><var>expression</var>. <var>Expression</var> should be an absolute expression (see <a href="Expressions.html#Expressions">Expressions</a>). If you just say <span class="samp">.text</span> then <span class="samp">.text 0</span> is assumed. Likewise <span class="samp">.data</span> means <span class="samp">.data 0</span>. Assembly begins in <code>text 0</code>. For instance: <pre class="smallexample"> .text 0 # The default subsection is text 0 anyway. .ascii "This lives in the first text subsection. *" .text 1 .ascii "But this lives in the second text subsection." .data 0 .ascii "This lives in the data section," .ascii "in the first data subsection." .text 0 .ascii "This lives in the first text section," .ascii "immediately following the asterisk (*)." </pre> <p>Each section has a <dfn>location counter</dfn> incremented by one for every byte assembled into that section. Because subsections are merely a convenience restricted to <span class="command">as</span> there is no concept of a subsection location counter. There is no way to directly manipulate a location counter—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 <dfn>active</dfn> location counter. </body></html>