toolchain/share/doc/as.html/i386_002dPrefixes.html

111 lines
6.4 KiB
HTML

<html lang="en">
<head>
<title>i386-Prefixes - 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="i386_002dDependent.html#i386_002dDependent" title="i386-Dependent">
<link rel="prev" href="i386_002dRegs.html#i386_002dRegs" title="i386-Regs">
<link rel="next" href="i386_002dMemory.html#i386_002dMemory" title="i386-Memory">
<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="i386-Prefixes"></a>
<a name="i386_002dPrefixes"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="i386_002dMemory.html#i386_002dMemory">i386-Memory</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="i386_002dRegs.html#i386_002dRegs">i386-Regs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="i386_002dDependent.html#i386_002dDependent">i386-Dependent</a>
<hr>
</div>
<h4 class="subsection">9.16.6 Instruction Prefixes</h4>
<p><a name="index-i386-instruction-prefixes-1211"></a><a name="index-instruction-prefixes_002c-i386-1212"></a><a name="index-prefixes_002c-i386-1213"></a>Instruction prefixes are used to modify the following instruction. They
are used to repeat string instructions, to provide section overrides, to
perform bus lock operations, and to change operand and address sizes.
(Most instructions that normally operate on 32-bit operands will use
16-bit operands if the instruction has an &ldquo;operand size&rdquo; prefix.)
Instruction prefixes are best written on the same line as the instruction
they act upon. For example, the &lsquo;<samp><span class="samp">scas</span></samp>&rsquo; (scan string) instruction is
repeated with:
<pre class="smallexample"> repne scas %es:(%edi),%al
</pre>
<p>You may also place prefixes on the lines immediately preceding the
instruction, but this circumvents checks that <code>as</code> does
with prefixes, and will not work with all prefixes.
<p>Here is a list of instruction prefixes:
<p><a name="index-section-override-prefixes_002c-i386-1214"></a>
<ul>
<li>Section override prefixes &lsquo;<samp><span class="samp">cs</span></samp>&rsquo;, &lsquo;<samp><span class="samp">ds</span></samp>&rsquo;, &lsquo;<samp><span class="samp">ss</span></samp>&rsquo;, &lsquo;<samp><span class="samp">es</span></samp>&rsquo;,
&lsquo;<samp><span class="samp">fs</span></samp>&rsquo;, &lsquo;<samp><span class="samp">gs</span></samp>&rsquo;. These are automatically added by specifying
using the <var>section</var>:<var>memory-operand</var> form for memory references.
<p><a name="index-size-prefixes_002c-i386-1215"></a><li>Operand/Address size prefixes &lsquo;<samp><span class="samp">data16</span></samp>&rsquo; and &lsquo;<samp><span class="samp">addr16</span></samp>&rsquo;
change 32-bit operands/addresses into 16-bit operands/addresses,
while &lsquo;<samp><span class="samp">data32</span></samp>&rsquo; and &lsquo;<samp><span class="samp">addr32</span></samp>&rsquo; change 16-bit ones (in a
<code>.code16</code> section) into 32-bit operands/addresses. These prefixes
<em>must</em> appear on the same line of code as the instruction they
modify. For example, in a 16-bit <code>.code16</code> section, you might
write:
<pre class="smallexample"> addr32 jmpl *(%ebx)
</pre>
<p><a name="index-bus-lock-prefixes_002c-i386-1216"></a><a name="index-inhibiting-interrupts_002c-i386-1217"></a><li>The bus lock prefix &lsquo;<samp><span class="samp">lock</span></samp>&rsquo; inhibits interrupts during execution of
the instruction it precedes. (This is only valid with certain
instructions; see a 80386 manual for details).
<p><a name="index-coprocessor-wait_002c-i386-1218"></a><li>The wait for coprocessor prefix &lsquo;<samp><span class="samp">wait</span></samp>&rsquo; waits for the coprocessor to
complete the current instruction. This should never be needed for the
80386/80387 combination.
<p><a name="index-repeat-prefixes_002c-i386-1219"></a><li>The &lsquo;<samp><span class="samp">rep</span></samp>&rsquo;, &lsquo;<samp><span class="samp">repe</span></samp>&rsquo;, and &lsquo;<samp><span class="samp">repne</span></samp>&rsquo; prefixes are added
to string instructions to make them repeat &lsquo;<samp><span class="samp">%ecx</span></samp>&rsquo; times (&lsquo;<samp><span class="samp">%cx</span></samp>&rsquo;
times if the current address size is 16-bits).
<a name="index-REX-prefixes_002c-i386-1220"></a><li>The &lsquo;<samp><span class="samp">rex</span></samp>&rsquo; family of prefixes is used by x86-64 to encode
extensions to i386 instruction set. The &lsquo;<samp><span class="samp">rex</span></samp>&rsquo; prefix has four
bits &mdash; an operand size overwrite (<code>64</code>) used to change operand size
from 32-bit to 64-bit and X, Y and Z extensions bits used to extend the
register set.
<p>You may write the &lsquo;<samp><span class="samp">rex</span></samp>&rsquo; prefixes directly. The &lsquo;<samp><span class="samp">rex64xyz</span></samp>&rsquo;
instruction emits &lsquo;<samp><span class="samp">rex</span></samp>&rsquo; prefix with all the bits set. By omitting
the <code>64</code>, <code>x</code>, <code>y</code> or <code>z</code> you may write other
prefixes as well. Normally, there is no need to write the prefixes
explicitly, since gas will automatically generate them based on the
instruction operands.
</ul>
</body></html>