You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
7.0KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU Assembler "as".
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Sub-Sections (Using as)</title>
  16. <meta name="description" content="Sub-Sections (Using as)">
  17. <meta name="keywords" content="Sub-Sections (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Sections.html#Sections" rel="up" title="Sections">
  25. <link href="bss.html#bss" rel="next" title="bss">
  26. <link href="As-Sections.html#As-Sections" rel="prev" title="As Sections">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="Sub_002dSections"></a>
  57. <div class="header">
  58. <p>
  59. 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>
  60. </div>
  61. <hr>
  62. <a name="Sub_002dSections-1"></a>
  63. <h3 class="section">4.4 Sub-Sections</h3>
  64. <a name="index-numbered-subsections"></a>
  65. <a name="index-grouping-data"></a>
  66. <p>Assembled bytes
  67. conventionally
  68. fall into two sections: text and data.
  69. You may have separate groups of
  70. data in named sections
  71. that you want to end up near to each other in the object file, even though they
  72. are not contiguous in the assembler source. <code>as</code> allows you to
  73. use <em>subsections</em> for this purpose. Within each section, there can be
  74. numbered subsections with values from 0 to 8192. Objects assembled into the
  75. same subsection go into the object file together with other objects in the same
  76. subsection. For example, a compiler might want to store constants in the text
  77. section, but might not want to have them interspersed with the program being
  78. assembled. In this case, the compiler could issue a &lsquo;<samp>.text 0</samp>&rsquo; before each
  79. section of code being output, and a &lsquo;<samp>.text 1</samp>&rsquo; before each group of
  80. constants being output.
  81. </p>
  82. <p>Subsections are optional. If you do not use subsections, everything
  83. goes in subsection number zero.
  84. </p>
  85. <p>Each subsection is zero-padded up to a multiple of four bytes.
  86. (Subsections may be padded a different amount on different flavors
  87. of <code>as</code>.)
  88. </p>
  89. <p>Subsections appear in your object file in numeric order, lowest numbered
  90. to highest. (All this to be compatible with other people&rsquo;s assemblers.)
  91. The object file contains no representation of subsections; <code>ld</code> and
  92. other programs that manipulate object files see no trace of them.
  93. They just see all your text subsections as a text section, and all your
  94. data subsections as a data section.
  95. </p>
  96. <p>To specify which subsection you want subsequent statements assembled
  97. into, use a numeric argument to specify it, in a &lsquo;<samp>.text
  98. <var>expression</var></samp>&rsquo; or a &lsquo;<samp>.data <var>expression</var></samp>&rsquo; statement.
  99. When generating COFF output, you
  100. can also use an extra subsection
  101. argument with arbitrary named sections: &lsquo;<samp>.section <var>name</var>,
  102. <var>expression</var></samp>&rsquo;.
  103. When generating ELF output, you
  104. can also use the <code>.subsection</code> directive (see <a href="SubSection.html#SubSection">SubSection</a>)
  105. to specify a subsection: &lsquo;<samp>.subsection <var>expression</var></samp>&rsquo;.
  106. <var>Expression</var> should be an absolute expression
  107. (see <a href="Expressions.html#Expressions">Expressions</a>). If you just say &lsquo;<samp>.text</samp>&rsquo; then &lsquo;<samp>.text 0</samp>&rsquo;
  108. is assumed. Likewise &lsquo;<samp>.data</samp>&rsquo; means &lsquo;<samp>.data 0</samp>&rsquo;. Assembly
  109. begins in <code>text 0</code>. For instance:
  110. </p><div class="smallexample">
  111. <pre class="smallexample">.text 0 # The default subsection is text 0 anyway.
  112. .ascii &quot;This lives in the first text subsection. *&quot;
  113. .text 1
  114. .ascii &quot;But this lives in the second text subsection.&quot;
  115. .data 0
  116. .ascii &quot;This lives in the data section,&quot;
  117. .ascii &quot;in the first data subsection.&quot;
  118. .text 0
  119. .ascii &quot;This lives in the first text section,&quot;
  120. .ascii &quot;immediately following the asterisk (*).&quot;
  121. </pre></div>
  122. <p>Each section has a <em>location counter</em> incremented by one for every byte
  123. assembled into that section. Because subsections are merely a convenience
  124. restricted to <code>as</code> there is no concept of a subsection location
  125. counter. There is no way to directly manipulate a location counter&mdash;but the
  126. <code>.align</code> directive changes it, and any label definition captures its
  127. current value. The location counter of the section where statements are being
  128. assembled is said to be the <em>active</em> location counter.
  129. </p>
  130. <hr>
  131. <div class="header">
  132. <p>
  133. 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>
  134. </div>
  135. </body>
  136. </html>