📄 macro.html
字号:
<html lang="en">
<head>
<title>Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
</head>
<body>
<div class="node">
<p>
Node:<a name="Macro">Macro</a>,
Next:<a rel="next" accesskey="n" href="MRI.html#MRI">MRI</a>,
Previous:<a rel="previous" accesskey="p" href="Long.html#Long">Long</a>,
Up:<a rel="up" accesskey="u" href="Pseudo-Ops.html#Pseudo%20Ops">Pseudo Ops</a>
<hr><br>
</div>
<h3 class="section"><code>.macro</code></h3>
<p>The commands <code>.macro</code> and <code>.endm</code> allow you to define macros that
generate assembly output. For example, this definition specifies a macro
<code>sum</code> that puts a sequence of numbers into memory:
<pre class="example"> .macro sum from=0, to=5
.long \from
.if \to-\from
sum "(\from+1)",\to
.endif
.endm
</pre>
<p>With that definition, <code>SUM 0,5</code> is equivalent to this assembly input:
<pre class="example"> .long 0
.long 1
.long 2
.long 3
.long 4
.long 5
</pre>
<dl>
<dt><code>.macro </code><var>macname</var><code></code>
<dd><dt><code>.macro </code><var>macname</var><code> </code><var>macargs</var><code> ...</code>
<dd>Begin the definition of a macro called <var>macname</var>. If your macro
definition requires arguments, specify their names after the macro name,
separated by commas or spaces. You can supply a default value for any
macro argument by following the name with <code>=</code><var>deflt</var><code></code>. For
example, these are all valid <code>.macro</code> statements:
<dl>
<dt><code>.macro comm</code>
<dd>Begin the definition of a macro called <code>comm</code>, which takes no
arguments.
<br><dt><code>.macro plus1 p, p1</code>
<dd><dt><code>.macro plus1 p p1</code>
<dd>Either statement begins the definition of a macro called <code>plus1</code>,
which takes two arguments; within the macro definition, write
<code>\p</code> or <code>\p1</code> to evaluate the arguments.
<br><dt><code>.macro reserve_str p1=0 p2</code>
<dd>Begin the definition of a macro called <code>reserve_str</code>, with two
arguments. The first argument has a default value, but not the second.
After the definition is complete, you can call the macro either as
<code>reserve_str </code><var>a</var><code>,</code><var>b</var><code></code> (with <code>\p1</code> evaluating to
<var>a</var> and <code>\p2</code> evaluating to <var>b</var>), or as <code>reserve_str
,</code><var>b</var><code></code> (with <code>\p1</code> evaluating as the default, in this case
<code>0</code>, and <code>\p2</code> evaluating to <var>b</var>).
</dl>
<p>When you call a macro, you can specify the argument values either by
position, or by keyword. For example, <code>sum 9,17</code> is equivalent to
<code>sum to=17, from=9</code>.
<br><dt><code>.endm</code>
<dd>Mark the end of a macro definition.
<br><dt><code>.exitm</code>
<dd>Exit early from the current macro definition.
<br><dt><code>\@</code>
<dd><code>as</code> maintains a counter of how many macros it has
executed in this pseudo-variable; you can copy that number to your
output with <code>\@</code>, but <em>only within a macro definition</em>.
</dl>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -