Symbol-Names.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: Symbol Names</title>
  15. <meta name="description" content="Using as: Symbol Names">
  16. <meta name="keywords" content="Using as: Symbol Names">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Symbols.html#Symbols" rel="up" title="Symbols">
  25. <link href="Dot.html#Dot" rel="next" title="Dot">
  26. <link href="Setting-Symbols.html#Setting-Symbols" rel="prev" title="Setting Symbols">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Symbol-Names"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Dot.html#Dot" accesskey="n" rel="next">Dot</a>, Previous: <a href="Setting-Symbols.html#Setting-Symbols" accesskey="p" rel="prev">Setting Symbols</a>, Up: <a href="Symbols.html#Symbols" accesskey="u" rel="up">Symbols</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>
  61. </div>
  62. <hr>
  63. <a name="Symbol-Names-1"></a>
  64. <h3 class="section">5.3 Symbol Names</h3>
  65. <a name="index-symbol-names"></a>
  66. <a name="index-names_002c-symbol"></a>
  67. <p>Symbol names begin with a letter or with one of &lsquo;<samp>._</samp>&rsquo;. On most
  68. machines, you can also use <code>$</code> in symbol names; exceptions are
  69. noted in <a href="Machine-Dependencies.html#Machine-Dependencies">Machine Dependencies</a>. That character may be followed by any
  70. string of digits, letters, dollar signs (unless otherwise noted for a
  71. particular target machine), and underscores.
  72. </p>
  73. <p>Case of letters is significant: <code>foo</code> is a different symbol name
  74. than <code>Foo</code>.
  75. </p>
  76. <p>Symbol names do not start with a digit. An exception to this rule is made for
  77. Local Labels. See below.
  78. </p>
  79. <p>Multibyte characters are supported. To generate a symbol name containing
  80. multibyte characters enclose it within double quotes and use escape codes. cf
  81. See <a href="Strings.html#Strings">Strings</a>. Generating a multibyte symbol name from a label is not
  82. currently supported.
  83. </p>
  84. <p>Each symbol has exactly one name. Each name in an assembly language program
  85. refers to exactly one symbol. You may use that symbol name any number of times
  86. in a program.
  87. </p>
  88. <a name="Local-Symbol-Names"></a>
  89. <h4 class="subheading">Local Symbol Names</h4>
  90. <a name="index-local-symbol-names"></a>
  91. <a name="index-symbol-names_002c-local"></a>
  92. <p>A local symbol is any symbol beginning with certain local label prefixes.
  93. By default, the local label prefix is &lsquo;<samp>.L</samp>&rsquo; for ELF systems or
  94. &lsquo;<samp>L</samp>&rsquo; for traditional a.out systems, but each target may have its own
  95. set of local label prefixes.
  96. On the HPPA local symbols begin with &lsquo;<samp>L$</samp>&rsquo;.
  97. </p>
  98. <p>Local symbols are defined and used within the assembler, but they are
  99. normally not saved in object files. Thus, they are not visible when debugging.
  100. You may use the &lsquo;<samp>-L</samp>&rsquo; option (see <a href="L.html#L">Include Local Symbols</a>)
  101. to retain the local symbols in the object files.
  102. </p>
  103. <a name="Local-Labels-1"></a>
  104. <h4 class="subheading">Local Labels</h4>
  105. <a name="index-local-labels"></a>
  106. <a name="index-temporary-symbol-names"></a>
  107. <a name="index-symbol-names_002c-temporary"></a>
  108. <p>Local labels are different from local symbols. Local labels help compilers and
  109. programmers use names temporarily. They create symbols which are guaranteed to
  110. be unique over the entire scope of the input source code and which can be
  111. referred to by a simple notation. To define a local label, write a label of
  112. the form &lsquo;<samp><b>N</b>:</samp>&rsquo; (where <b>N</b> represents any non-negative integer).
  113. To refer to the most recent previous definition of that label write
  114. &lsquo;<samp><b>N</b>b</samp>&rsquo;, using the same number as when you defined the label. To refer
  115. to the next definition of a local label, write &lsquo;<samp><b>N</b>f</samp>&rsquo;. The &lsquo;<samp>b</samp>&rsquo;
  116. stands for &ldquo;backwards&rdquo; and the &lsquo;<samp>f</samp>&rsquo; stands for &ldquo;forwards&rdquo;.
  117. </p>
  118. <p>There is no restriction on how you can use these labels, and you can reuse them
  119. too. So that it is possible to repeatedly define the same local label (using
  120. the same number &lsquo;<samp><b>N</b></samp>&rsquo;), although you can only refer to the most recently
  121. defined local label of that number (for a backwards reference) or the next
  122. definition of a specific local label for a forward reference. It is also worth
  123. noting that the first 10 local labels (&lsquo;<samp><b>0:</b></samp>&rsquo;&hellip;&lsquo;<samp><b>9:</b></samp>&rsquo;) are
  124. implemented in a slightly more efficient manner than the others.
  125. </p>
  126. <p>Here is an example:
  127. </p>
  128. <div class="smallexample">
  129. <pre class="smallexample">1: branch 1f
  130. 2: branch 1b
  131. 1: branch 2f
  132. 2: branch 1b
  133. </pre></div>
  134. <p>Which is the equivalent of:
  135. </p>
  136. <div class="smallexample">
  137. <pre class="smallexample">label_1: branch label_3
  138. label_2: branch label_1
  139. label_3: branch label_4
  140. label_4: branch label_3
  141. </pre></div>
  142. <p>Local label names are only a notational device. They are immediately
  143. transformed into more conventional symbol names before the assembler uses them.
  144. The symbol names are stored in the symbol table, appear in error messages, and
  145. are optionally emitted to the object file. The names are constructed using
  146. these parts:
  147. </p>
  148. <dl compact="compact">
  149. <dt><code><em>local label prefix</em></code></dt>
  150. <dd><p>All local symbols begin with the system-specific local label prefix.
  151. Normally both <code>as</code> and <code>ld</code> forget symbols
  152. that start with the local label prefix. These labels are
  153. used for symbols you are never intended to see. If you use the
  154. &lsquo;<samp>-L</samp>&rsquo; option then <code>as</code> retains these symbols in the
  155. object file. If you also instruct <code>ld</code> to retain these symbols,
  156. you may use them in debugging.
  157. </p>
  158. </dd>
  159. <dt><code><var>number</var></code></dt>
  160. <dd><p>This is the number that was used in the local label definition. So if the
  161. label is written &lsquo;<samp>55:</samp>&rsquo; then the number is &lsquo;<samp>55</samp>&rsquo;.
  162. </p>
  163. </dd>
  164. <dt><code><kbd>C-B</kbd></code></dt>
  165. <dd><p>This unusual character is included so you do not accidentally invent a symbol
  166. of the same name. The character has ASCII value of &lsquo;<samp>\002</samp>&rsquo; (control-B).
  167. </p>
  168. </dd>
  169. <dt><code><em>ordinal number</em></code></dt>
  170. <dd><p>This is a serial number to keep the labels distinct. The first definition of
  171. &lsquo;<samp>0:</samp>&rsquo; gets the number &lsquo;<samp>1</samp>&rsquo;. The 15th definition of &lsquo;<samp>0:</samp>&rsquo; gets the
  172. number &lsquo;<samp>15</samp>&rsquo;, and so on. Likewise the first definition of &lsquo;<samp>1:</samp>&rsquo; gets
  173. the number &lsquo;<samp>1</samp>&rsquo; and its 15th definition gets &lsquo;<samp>15</samp>&rsquo; as well.
  174. </p></dd>
  175. </dl>
  176. <p>So for example, the first <code>1:</code> may be named <code>.L1<kbd>C-B</kbd>1</code>, and
  177. the 44th <code>3:</code> may be named <code>.L3<kbd>C-B</kbd>44</code>.
  178. </p>
  179. <a name="Dollar-Local-Labels"></a>
  180. <h4 class="subheading">Dollar Local Labels</h4>
  181. <a name="index-dollar-local-symbols"></a>
  182. <p>On some targets <code>as</code> also supports an even more local form of
  183. local labels called dollar labels. These labels go out of scope (i.e., they
  184. become undefined) as soon as a non-local label is defined. Thus they remain
  185. valid for only a small region of the input source code. Normal local labels,
  186. by contrast, remain in scope for the entire file, or until they are redefined
  187. by another occurrence of the same local label.
  188. </p>
  189. <p>Dollar labels are defined in exactly the same way as ordinary local labels,
  190. except that they have a dollar sign suffix to their numeric value, e.g.,
  191. &lsquo;<samp><b>55$:</b></samp>&rsquo;.
  192. </p>
  193. <p>They can also be distinguished from ordinary local labels by their transformed
  194. names which use ASCII character &lsquo;<samp>\001</samp>&rsquo; (control-A) as the magic character
  195. to distinguish them from ordinary labels. For example, the fifth definition of
  196. &lsquo;<samp>6$</samp>&rsquo; may be named &lsquo;<samp>.L6<kbd>C-A</kbd>5</samp>&rsquo;.
  197. </p>
  198. <hr>
  199. <div class="header">
  200. <p>
  201. Next: <a href="Dot.html#Dot" accesskey="n" rel="next">Dot</a>, Previous: <a href="Setting-Symbols.html#Setting-Symbols" accesskey="p" rel="prev">Setting Symbols</a>, Up: <a href="Symbols.html#Symbols" accesskey="u" rel="up">Symbols</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>
  202. </div>
  203. </body>
  204. </html>