TIC54X_002dSubsyms.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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: TIC54X-Subsyms</title>
  15. <meta name="description" content="Using as: TIC54X-Subsyms">
  16. <meta name="keywords" content="Using as: TIC54X-Subsyms">
  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="TIC54X_002dDependent.html#TIC54X_002dDependent" rel="up" title="TIC54X-Dependent">
  25. <link href="TIC54X_002dLocals.html#TIC54X_002dLocals" rel="next" title="TIC54X-Locals">
  26. <link href="TIC54X_002dConstants.html#TIC54X_002dConstants" rel="prev" title="TIC54X-Constants">
  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="TIC54X_002dSubsyms"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="TIC54X_002dLocals.html#TIC54X_002dLocals" accesskey="n" rel="next">TIC54X-Locals</a>, Previous: <a href="TIC54X_002dConstants.html#TIC54X_002dConstants" accesskey="p" rel="prev">TIC54X-Constants</a>, Up: <a href="TIC54X_002dDependent.html#TIC54X_002dDependent" accesskey="u" rel="up">TIC54X-Dependent</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="String-Substitution"></a>
  64. <h4 class="subsection">9.44.5 String Substitution</h4>
  65. <p>A subset of allowable symbols (which we&rsquo;ll call subsyms) may be assigned
  66. arbitrary string values. This is roughly equivalent to C preprocessor
  67. #define macros. When <code>as</code> encounters one of these
  68. symbols, the symbol is replaced in the input stream by its string value.
  69. Subsym names <strong>must</strong> begin with a letter.
  70. </p>
  71. <p>Subsyms may be defined using the <code>.asg</code> and <code>.eval</code> directives
  72. (See <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.asg</code></a>,
  73. See <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.eval</code></a>.
  74. </p>
  75. <p>Expansion is recursive until a previously encountered symbol is seen, at
  76. which point substitution stops.
  77. </p>
  78. <p>In this example, x is replaced with SYM2; SYM2 is replaced with SYM1, and SYM1
  79. is replaced with x. At this point, x has already been encountered
  80. and the substitution stops.
  81. </p>
  82. <div class="smallexample">
  83. <pre class="smallexample"> .asg &quot;x&quot;,SYM1
  84. .asg &quot;SYM1&quot;,SYM2
  85. .asg &quot;SYM2&quot;,x
  86. add x,a ; final code assembled is &quot;add x, a&quot;
  87. </pre></div>
  88. <p>Macro parameters are converted to subsyms; a side effect of this is the normal
  89. <code>as</code> &rsquo;\ARG&rsquo; dereferencing syntax is unnecessary. Subsyms
  90. defined within a macro will have global scope, unless the <code>.var</code>
  91. directive is used to identify the subsym as a local macro variable
  92. see <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.var</code></a>.
  93. </p>
  94. <p>Substitution may be forced in situations where replacement might be
  95. ambiguous by placing colons on either side of the subsym. The following
  96. code:
  97. </p>
  98. <div class="smallexample">
  99. <pre class="smallexample"> .eval &quot;10&quot;,x
  100. LAB:X: add #x, a
  101. </pre></div>
  102. <p>When assembled becomes:
  103. </p>
  104. <div class="smallexample">
  105. <pre class="smallexample">LAB10 add #10, a
  106. </pre></div>
  107. <p>Smaller parts of the string assigned to a subsym may be accessed with
  108. the following syntax:
  109. </p>
  110. <dl compact="compact">
  111. <dt><code><code>:<var>symbol</var>(<var>char_index</var>):</code></code></dt>
  112. <dd><p>Evaluates to a single-character string, the character at <var>char_index</var>.
  113. </p></dd>
  114. <dt><code><code>:<var>symbol</var>(<var>start</var>,<var>length</var>):</code></code></dt>
  115. <dd><p>Evaluates to a substring of <var>symbol</var> beginning at <var>start</var> with
  116. length <var>length</var>.
  117. </p></dd>
  118. </dl>
  119. <hr>
  120. <div class="header">
  121. <p>
  122. Next: <a href="TIC54X_002dLocals.html#TIC54X_002dLocals" accesskey="n" rel="next">TIC54X-Locals</a>, Previous: <a href="TIC54X_002dConstants.html#TIC54X_002dConstants" accesskey="p" rel="prev">TIC54X-Constants</a>, Up: <a href="TIC54X_002dDependent.html#TIC54X_002dDependent" accesskey="u" rel="up">TIC54X-Dependent</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>
  123. </div>
  124. </body>
  125. </html>