toolchain/share/doc/as.html/TIC54X_002dSubsyms.html

101 lines
4.4 KiB
HTML
Raw Normal View History

2024-01-10 05:24:32 +00:00
<html lang="en">
<head>
<title>TIC54X-Subsyms - Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="TIC54X_002dDependent.html#TIC54X_002dDependent" title="TIC54X-Dependent">
<link rel="prev" href="TIC54X_002dConstants.html#TIC54X_002dConstants" title="TIC54X-Constants">
<link rel="next" href="TIC54X_002dLocals.html#TIC54X_002dLocals" title="TIC54X-Locals">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU Assembler "as".
Copyright (C) 1991-2019 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''.
-->
<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; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="TIC54X-Subsyms"></a>
<a name="TIC54X_002dSubsyms"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="TIC54X_002dLocals.html#TIC54X_002dLocals">TIC54X-Locals</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="TIC54X_002dConstants.html#TIC54X_002dConstants">TIC54X-Constants</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="TIC54X_002dDependent.html#TIC54X_002dDependent">TIC54X-Dependent</a>
<hr>
</div>
<h4 class="subsection">9.45.5 String Substitution</h4>
<p>A subset of allowable symbols (which we'll call subsyms) may be assigned
arbitrary string values. This is roughly equivalent to C preprocessor
#define macros. When <code>as</code> encounters one of these
symbols, the symbol is replaced in the input stream by its string value.
Subsym names <strong>must</strong> begin with a letter.
<p>Subsyms may be defined using the <code>.asg</code> and <code>.eval</code> directives
(See <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.asg</code></a>,
See <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.eval</code></a>.
<p>Expansion is recursive until a previously encountered symbol is seen, at
which point substitution stops.
<p>In this example, x is replaced with SYM2; SYM2 is replaced with SYM1, and SYM1
is replaced with x. At this point, x has already been encountered
and the substitution stops.
<pre class="smallexample"> .asg "x",SYM1
.asg "SYM1",SYM2
.asg "SYM2",x
add x,a ; final code assembled is "add x, a"
</pre>
<p>Macro parameters are converted to subsyms; a side effect of this is the normal
<code>as</code> '\ARG' dereferencing syntax is unnecessary. Subsyms
defined within a macro will have global scope, unless the <code>.var</code>
directive is used to identify the subsym as a local macro variable
see <a href="TIC54X_002dDirectives.html#TIC54X_002dDirectives"><code>.var</code></a>.
<p>Substitution may be forced in situations where replacement might be
ambiguous by placing colons on either side of the subsym. The following
code:
<pre class="smallexample"> .eval "10",x
LAB:X: add #x, a
</pre>
<p>When assembled becomes:
<pre class="smallexample"> LAB10 add #10, a
</pre>
<p>Smaller parts of the string assigned to a subsym may be accessed with
the following syntax:
<dl>
<dt><code>:</code><var>symbol</var><code>(</code><var>char_index</var><code>):</code><dd>Evaluates to a single-character string, the character at <var>char_index</var>.
<br><dt><code>:</code><var>symbol</var><code>(</code><var>start</var><code>,</code><var>length</var><code>):</code><dd>Evaluates to a substring of <var>symbol</var> beginning at <var>start</var> with
length <var>length</var>.
</dl>
</body></html>