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
5Copyright (C) 1991-2021 Free Software Foundation, Inc.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3
9or any later version published by the Free Software Foundation;
10with no Invariant Sections, with no Front-Cover Texts, and with no
11Back-Cover Texts.  A copy of the license is included in the
12section entitled "GNU Free Documentation License".
13 -->
14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
15<head>
16<title>Using as: MIPS Macros</title>
17
18<meta name="description" content="Using as: MIPS Macros">
19<meta name="keywords" content="Using as: MIPS Macros">
20<meta name="resource-type" content="document">
21<meta name="distribution" content="global">
22<meta name="Generator" content="makeinfo">
23<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24<link href="index.html#Top" rel="start" title="Top">
25<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
26<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
27<link href="MIPS_002dDependent.html#MIPS_002dDependent" rel="up" title="MIPS-Dependent">
28<link href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" rel="next" title="MIPS Symbol Sizes">
29<link href="MIPS-Options.html#MIPS-Options" rel="previous" title="MIPS Options">
30<style type="text/css">
31<!--
32a.summary-letter {text-decoration: none}
33blockquote.smallquotation {font-size: smaller}
34div.display {margin-left: 3.2em}
35div.example {margin-left: 3.2em}
36div.indentedblock {margin-left: 3.2em}
37div.lisp {margin-left: 3.2em}
38div.smalldisplay {margin-left: 3.2em}
39div.smallexample {margin-left: 3.2em}
40div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
41div.smalllisp {margin-left: 3.2em}
42kbd {font-style:oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47pre.smalldisplay {font-family: inherit; font-size: smaller}
48pre.smallexample {font-size: smaller}
49pre.smallformat {font-family: inherit; font-size: smaller}
50pre.smalllisp {font-size: smaller}
51span.nocodebreak {white-space:nowrap}
52span.nolinebreak {white-space:nowrap}
53span.roman {font-family:serif; font-weight:normal}
54span.sansserif {font-family:sans-serif; font-weight:normal}
55ul.no-bullet {list-style: none}
56-->
57</style>
58
59
60</head>
61
62<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
63<a name="MIPS-Macros"></a>
64<div class="header">
65<p>
66Next: <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" accesskey="n" rel="next">MIPS Symbol Sizes</a>, Previous: <a href="MIPS-Options.html#MIPS-Options" accesskey="p" rel="previous">MIPS Options</a>, Up: <a href="MIPS_002dDependent.html#MIPS_002dDependent" accesskey="u" rel="up">MIPS-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>
67</div>
68<hr>
69<a name="High_002dlevel-assembly-macros"></a>
70<h4 class="subsection">9.27.2 High-level assembly macros</h4>
71
72<p>MIPS assemblers have traditionally provided a wider range of
73instructions than the MIPS architecture itself.  These extra
74instructions are usually referred to as &ldquo;macro&rdquo; instructions
75<a name="DOCF2" href="#FOOT2"><sup>2</sup></a>.
76</p>
77<p>Some MIPS macro instructions extend an underlying architectural instruction
78while others are entirely new.  An example of the former type is <code>and</code>,
79which allows the third operand to be either a register or an arbitrary
80immediate value.  Examples of the latter type include <code>bgt</code>, which
81branches to the third operand when the first operand is greater than
82the second operand, and <code>ulh</code>, which implements an unaligned
832-byte load.
84</p>
85<p>One of the most common extensions provided by macros is to expand
86memory offsets to the full address range (32 or 64 bits) and to allow
87symbolic offsets such as &lsquo;<samp>my_data + 4</samp>&rsquo; to be used in place of
88integer constants.  For example, the architectural instruction
89<code>lbu</code> allows only a signed 16-bit offset, whereas the macro
90<code>lbu</code> allows code such as &lsquo;<samp>lbu $4,array+32769($5)</samp>&rsquo;.
91The implementation of these symbolic offsets depends on several factors,
92such as whether the assembler is generating SVR4-style PIC (selected by
93<samp>-KPIC</samp>, see <a href="MIPS-Options.html#MIPS-Options">Assembler options</a>), the size of symbols
94(see <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes">Directives to override the size of symbols</a>),
95and the small data limit (see <a href="MIPS-Small-Data.html#MIPS-Small-Data">Controlling the use
96of small data accesses</a>).
97</p>
98<a name="index-_002eset-macro"></a>
99<a name="index-_002eset-nomacro"></a>
100<p>Sometimes it is undesirable to have one assembly instruction expand
101to several machine instructions.  The directive <code>.set nomacro</code>
102tells the assembler to warn when this happens.  <code>.set macro</code>
103restores the default behavior.
104</p>
105<a name="index-at-register_002c-MIPS"></a>
106<a name="index-_002eset-at_003dreg"></a>
107<p>Some macro instructions need a temporary register to store intermediate
108results.  This register is usually <code>$1</code>, also known as <code>$at</code>,
109but it can be changed to any core register <var>reg</var> using
110<code>.set at=<var>reg</var></code>.  Note that <code>$at</code> always refers
111to <code>$1</code> regardless of which register is being used as the
112temporary register.
113</p>
114<a name="index-_002eset-at"></a>
115<a name="index-_002eset-noat"></a>
116<p>Implicit uses of the temporary register in macros could interfere with
117explicit uses in the assembly code.  The assembler therefore warns
118whenever it sees an explicit use of the temporary register.  The directive
119<code>.set noat</code> silences this warning while <code>.set at</code> restores
120the default behavior.  It is safe to use <code>.set noat</code> while
121<code>.set nomacro</code> is in effect since single-instruction macros
122never need a temporary register.
123</p>
124<p>Note that while the <small>GNU</small> assembler provides these macros for compatibility,
125it does not make any attempt to optimize them with the surrounding code.
126</p>
127<div class="footnote">
128<hr>
129<h4 class="footnotes-heading">Footnotes</h4>
130
131<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3>
132<p>The term &ldquo;macro&rdquo; is somewhat overloaded here, since
133these macros have no relation to those defined by <code>.macro</code>,
134see <a href="Macro.html#Macro"><code>.macro</code></a>.</p>
135</div>
136<hr>
137<div class="header">
138<p>
139Next: <a href="MIPS-Symbol-Sizes.html#MIPS-Symbol-Sizes" accesskey="n" rel="next">MIPS Symbol Sizes</a>, Previous: <a href="MIPS-Options.html#MIPS-Options" accesskey="p" rel="previous">MIPS Options</a>, Up: <a href="MIPS_002dDependent.html#MIPS_002dDependent" accesskey="u" rel="up">MIPS-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>
140</div>
141
142
143
144</body>
145</html>
146