blob: 241775470dd2d3a9dea748a9da90649db3b97795 [file] [log] [blame]
<html lang="en">
<head>
<title>i386-Mnemonics - 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_002dSyntax.html#i386_002dSyntax" title="i386-Syntax">
<link rel="next" href="i386_002dRegs.html#i386_002dRegs" title="i386-Regs">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU Assembler "as".
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2006, 2007, 2008, 2009, 2010 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>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="i386-Mnemonics"></a>
<a name="i386_002dMnemonics"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="i386_002dRegs.html#i386_002dRegs">i386-Regs</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="i386_002dSyntax.html#i386_002dSyntax">i386-Syntax</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="i386_002dDependent.html#i386_002dDependent">i386-Dependent</a>
<hr>
</div>
<h4 class="subsection">9.13.4 Instruction Naming</h4>
<p><a name="index-i386-instruction-naming-916"></a><a name="index-instruction-naming_002c-i386-917"></a><a name="index-x86_002d64-instruction-naming-918"></a><a name="index-instruction-naming_002c-x86_002d64-919"></a>
Instruction mnemonics are suffixed with one character modifiers which
specify the size of operands. The letters &lsquo;<samp><span class="samp">b</span></samp>&rsquo;, &lsquo;<samp><span class="samp">w</span></samp>&rsquo;, &lsquo;<samp><span class="samp">l</span></samp>&rsquo;
and &lsquo;<samp><span class="samp">q</span></samp>&rsquo; specify byte, word, long and quadruple word operands. If
no suffix is specified by an instruction then <code>as</code> tries to
fill in the missing suffix based on the destination register operand
(the last one by convention). Thus, &lsquo;<samp><span class="samp">mov %ax, %bx</span></samp>&rsquo; is equivalent
to &lsquo;<samp><span class="samp">movw %ax, %bx</span></samp>&rsquo;; also, &lsquo;<samp><span class="samp">mov $1, %bx</span></samp>&rsquo; is equivalent to
&lsquo;<samp><span class="samp">movw $1, bx</span></samp>&rsquo;. Note that this is incompatible with the AT&amp;T Unix
assembler which assumes that a missing mnemonic suffix implies long
operand size. (This incompatibility does not affect compiler output
since compilers always explicitly specify the mnemonic suffix.)
<p>Almost all instructions have the same names in AT&amp;T and Intel format.
There are a few exceptions. The sign extend and zero extend
instructions need two sizes to specify them. They need a size to
sign/zero extend <em>from</em> and a size to zero extend <em>to</em>. This
is accomplished by using two instruction mnemonic suffixes in AT&amp;T
syntax. Base names for sign extend and zero extend are
&lsquo;<samp><span class="samp">movs...</span></samp>&rsquo; and &lsquo;<samp><span class="samp">movz...</span></samp>&rsquo; in AT&amp;T syntax (&lsquo;<samp><span class="samp">movsx</span></samp>&rsquo;
and &lsquo;<samp><span class="samp">movzx</span></samp>&rsquo; in Intel syntax). The instruction mnemonic suffixes
are tacked on to this base name, the <em>from</em> suffix before the
<em>to</em> suffix. Thus, &lsquo;<samp><span class="samp">movsbl %al, %edx</span></samp>&rsquo; is AT&amp;T syntax for
&ldquo;move sign extend <em>from</em> %al <em>to</em> %edx.&rdquo; Possible suffixes,
thus, are &lsquo;<samp><span class="samp">bl</span></samp>&rsquo; (from byte to long), &lsquo;<samp><span class="samp">bw</span></samp>&rsquo; (from byte to word),
&lsquo;<samp><span class="samp">wl</span></samp>&rsquo; (from word to long), &lsquo;<samp><span class="samp">bq</span></samp>&rsquo; (from byte to quadruple word),
&lsquo;<samp><span class="samp">wq</span></samp>&rsquo; (from word to quadruple word), and &lsquo;<samp><span class="samp">lq</span></samp>&rsquo; (from long to
quadruple word).
<p><a name="index-encoding-options_002c-i386-920"></a><a name="index-encoding-options_002c-x86_002d64-921"></a>
Different encoding options can be specified via optional mnemonic
suffix. &lsquo;<samp><span class="samp">.s</span></samp>&rsquo; suffix swaps 2 register operands in encoding when
moving from one register to another.
<p><a name="index-conversion-instructions_002c-i386-922"></a><a name="index-i386-conversion-instructions-923"></a><a name="index-conversion-instructions_002c-x86_002d64-924"></a><a name="index-x86_002d64-conversion-instructions-925"></a>The Intel-syntax conversion instructions
<ul>
<li>&lsquo;<samp><span class="samp">cbw</span></samp>&rsquo; &mdash; sign-extend byte in &lsquo;<samp><span class="samp">%al</span></samp>&rsquo; to word in &lsquo;<samp><span class="samp">%ax</span></samp>&rsquo;,
<li>&lsquo;<samp><span class="samp">cwde</span></samp>&rsquo; &mdash; sign-extend word in &lsquo;<samp><span class="samp">%ax</span></samp>&rsquo; to long in &lsquo;<samp><span class="samp">%eax</span></samp>&rsquo;,
<li>&lsquo;<samp><span class="samp">cwd</span></samp>&rsquo; &mdash; sign-extend word in &lsquo;<samp><span class="samp">%ax</span></samp>&rsquo; to long in &lsquo;<samp><span class="samp">%dx:%ax</span></samp>&rsquo;,
<li>&lsquo;<samp><span class="samp">cdq</span></samp>&rsquo; &mdash; sign-extend dword in &lsquo;<samp><span class="samp">%eax</span></samp>&rsquo; to quad in &lsquo;<samp><span class="samp">%edx:%eax</span></samp>&rsquo;,
<li>&lsquo;<samp><span class="samp">cdqe</span></samp>&rsquo; &mdash; sign-extend dword in &lsquo;<samp><span class="samp">%eax</span></samp>&rsquo; to quad in &lsquo;<samp><span class="samp">%rax</span></samp>&rsquo;
(x86-64 only),
<li>&lsquo;<samp><span class="samp">cqo</span></samp>&rsquo; &mdash; sign-extend quad in &lsquo;<samp><span class="samp">%rax</span></samp>&rsquo; to octuple in
&lsquo;<samp><span class="samp">%rdx:%rax</span></samp>&rsquo; (x86-64 only),
</ul>
<p class="noindent">are called &lsquo;<samp><span class="samp">cbtw</span></samp>&rsquo;, &lsquo;<samp><span class="samp">cwtl</span></samp>&rsquo;, &lsquo;<samp><span class="samp">cwtd</span></samp>&rsquo;, &lsquo;<samp><span class="samp">cltd</span></samp>&rsquo;, &lsquo;<samp><span class="samp">cltq</span></samp>&rsquo;, and
&lsquo;<samp><span class="samp">cqto</span></samp>&rsquo; in AT&amp;T naming. <code>as</code> accepts either naming for these
instructions.
<p><a name="index-jump-instructions_002c-i386-926"></a><a name="index-call-instructions_002c-i386-927"></a><a name="index-jump-instructions_002c-x86_002d64-928"></a><a name="index-call-instructions_002c-x86_002d64-929"></a>Far call/jump instructions are &lsquo;<samp><span class="samp">lcall</span></samp>&rsquo; and &lsquo;<samp><span class="samp">ljmp</span></samp>&rsquo; in
AT&amp;T syntax, but are &lsquo;<samp><span class="samp">call far</span></samp>&rsquo; and &lsquo;<samp><span class="samp">jump far</span></samp>&rsquo; in Intel
convention.
<h4 class="subsection">9.13.5 AT&amp;T Mnemonic versus Intel Mnemonic</h4>
<p><a name="index-i386-mnemonic-compatibility-930"></a><a name="index-mnemonic-compatibility_002c-i386-931"></a>
<code>as</code> supports assembly using Intel mnemonic.
<code>.intel_mnemonic</code> selects Intel mnemonic with Intel syntax, and
<code>.att_mnemonic</code> switches back to the usual AT&amp;T mnemonic with AT&amp;T
syntax for compatibility with the output of <code>gcc</code>.
Several x87 instructions, &lsquo;<samp><span class="samp">fadd</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fdiv</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fdivp</span></samp>&rsquo;,
&lsquo;<samp><span class="samp">fdivr</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fdivrp</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fmul</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fsub</span></samp>&rsquo;, &lsquo;<samp><span class="samp">fsubp</span></samp>&rsquo;,
&lsquo;<samp><span class="samp">fsubr</span></samp>&rsquo; and &lsquo;<samp><span class="samp">fsubrp</span></samp>&rsquo;, are implemented in AT&amp;T System V/386
assembler with different mnemonics from those in Intel IA32 specification.
<code>gcc</code> generates those instructions with AT&amp;T mnemonic.
</body></html>