i386_002dVariations.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: i386-Variations</title>
  15. <meta name="description" content="Using as: i386-Variations">
  16. <meta name="keywords" content="Using as: i386-Variations">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="i386_002dSyntax.html#i386_002dSyntax" rel="up" title="i386-Syntax">
  25. <link href="i386_002dChars.html#i386_002dChars" rel="next" title="i386-Chars">
  26. <link href="i386_002dSyntax.html#i386_002dSyntax" rel="previous" title="i386-Syntax">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style:oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="i386_002dVariations"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="i386_002dChars.html#i386_002dChars" accesskey="n" rel="next">i386-Chars</a>, Up: <a href="i386_002dSyntax.html#i386_002dSyntax" accesskey="u" rel="up">i386-Syntax</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>
  61. </div>
  62. <hr>
  63. <a name="AT_0026T-Syntax-versus-Intel-Syntax"></a>
  64. <h4 class="subsubsection">9.16.3.1 AT&amp;T Syntax versus Intel Syntax</h4>
  65. <a name="index-i386-intel_005fsyntax-pseudo-op"></a>
  66. <a name="index-intel_005fsyntax-pseudo-op_002c-i386"></a>
  67. <a name="index-i386-att_005fsyntax-pseudo-op"></a>
  68. <a name="index-att_005fsyntax-pseudo-op_002c-i386"></a>
  69. <a name="index-i386-syntax-compatibility"></a>
  70. <a name="index-syntax-compatibility_002c-i386"></a>
  71. <a name="index-x86_002d64-intel_005fsyntax-pseudo-op"></a>
  72. <a name="index-intel_005fsyntax-pseudo-op_002c-x86_002d64"></a>
  73. <a name="index-x86_002d64-att_005fsyntax-pseudo-op"></a>
  74. <a name="index-att_005fsyntax-pseudo-op_002c-x86_002d64"></a>
  75. <a name="index-x86_002d64-syntax-compatibility"></a>
  76. <a name="index-syntax-compatibility_002c-x86_002d64"></a>
  77. <p><code>as</code> now supports assembly using Intel assembler syntax.
  78. <code>.intel_syntax</code> selects Intel mode, and <code>.att_syntax</code> switches
  79. back to the usual AT&amp;T mode for compatibility with the output of
  80. <code>gcc</code>. Either of these directives may have an optional
  81. argument, <code>prefix</code>, or <code>noprefix</code> specifying whether registers
  82. require a &lsquo;<samp>%</samp>&rsquo; prefix. AT&amp;T System V/386 assembler syntax is quite
  83. different from Intel syntax. We mention these differences because
  84. almost all 80386 documents use Intel syntax. Notable differences
  85. between the two syntaxes are:
  86. </p>
  87. <a name="index-immediate-operands_002c-i386"></a>
  88. <a name="index-i386-immediate-operands"></a>
  89. <a name="index-register-operands_002c-i386"></a>
  90. <a name="index-i386-register-operands"></a>
  91. <a name="index-jump_002fcall-operands_002c-i386"></a>
  92. <a name="index-i386-jump_002fcall-operands"></a>
  93. <a name="index-operand-delimiters_002c-i386"></a>
  94. <a name="index-immediate-operands_002c-x86_002d64"></a>
  95. <a name="index-x86_002d64-immediate-operands"></a>
  96. <a name="index-register-operands_002c-x86_002d64"></a>
  97. <a name="index-x86_002d64-register-operands"></a>
  98. <a name="index-jump_002fcall-operands_002c-x86_002d64"></a>
  99. <a name="index-x86_002d64-jump_002fcall-operands"></a>
  100. <a name="index-operand-delimiters_002c-x86_002d64"></a>
  101. <ul>
  102. <li> AT&amp;T immediate operands are preceded by &lsquo;<samp>$</samp>&rsquo;; Intel immediate
  103. operands are undelimited (Intel &lsquo;<samp>push 4</samp>&rsquo; is AT&amp;T &lsquo;<samp>pushl $4</samp>&rsquo;).
  104. AT&amp;T register operands are preceded by &lsquo;<samp>%</samp>&rsquo;; Intel register operands
  105. are undelimited. AT&amp;T absolute (as opposed to PC relative) jump/call
  106. operands are prefixed by &lsquo;<samp>*</samp>&rsquo;; they are undelimited in Intel syntax.
  107. </li><li> <a name="index-i386-source_002c-destination-operands"></a>
  108. <a name="index-source_002c-destination-operands_003b-i386"></a>
  109. <a name="index-x86_002d64-source_002c-destination-operands"></a>
  110. <a name="index-source_002c-destination-operands_003b-x86_002d64"></a>
  111. AT&amp;T and Intel syntax use the opposite order for source and destination
  112. operands. Intel &lsquo;<samp>add eax, 4</samp>&rsquo; is &lsquo;<samp>addl $4, %eax</samp>&rsquo;. The
  113. &lsquo;<samp>source, dest</samp>&rsquo; convention is maintained for compatibility with
  114. previous Unix assemblers. Note that &lsquo;<samp>bound</samp>&rsquo;, &lsquo;<samp>invlpga</samp>&rsquo;, and
  115. instructions with 2 immediate operands, such as the &lsquo;<samp>enter</samp>&rsquo;
  116. instruction, do <em>not</em> have reversed order. <a href="i386_002dBugs.html#i386_002dBugs">i386-Bugs</a>.
  117. </li><li> <a name="index-mnemonic-suffixes_002c-i386"></a>
  118. <a name="index-sizes-operands_002c-i386"></a>
  119. <a name="index-i386-size-suffixes"></a>
  120. <a name="index-mnemonic-suffixes_002c-x86_002d64"></a>
  121. <a name="index-sizes-operands_002c-x86_002d64"></a>
  122. <a name="index-x86_002d64-size-suffixes"></a>
  123. In AT&amp;T syntax the size of memory operands is determined from the last
  124. character of the instruction mnemonic. Mnemonic suffixes of &lsquo;<samp>b</samp>&rsquo;,
  125. &lsquo;<samp>w</samp>&rsquo;, &lsquo;<samp>l</samp>&rsquo; and &lsquo;<samp>q</samp>&rsquo; specify byte (8-bit), word (16-bit), long
  126. (32-bit) and quadruple word (64-bit) memory references. Mnemonic suffixes
  127. of &lsquo;<samp>x</samp>&rsquo;, &lsquo;<samp>y</samp>&rsquo; and &lsquo;<samp>z</samp>&rsquo; specify xmm (128-bit vector), ymm
  128. (256-bit vector) and zmm (512-bit vector) memory references, only when there&rsquo;s
  129. no other way to disambiguate an instruction. Intel syntax accomplishes this by
  130. prefixing memory operands (<em>not</em> the instruction mnemonics) with
  131. &lsquo;<samp>byte ptr</samp>&rsquo;, &lsquo;<samp>word ptr</samp>&rsquo;, &lsquo;<samp>dword ptr</samp>&rsquo;, &lsquo;<samp>qword ptr</samp>&rsquo;,
  132. &lsquo;<samp>xmmword ptr</samp>&rsquo;, &lsquo;<samp>ymmword ptr</samp>&rsquo; and &lsquo;<samp>zmmword ptr</samp>&rsquo;. Thus, Intel
  133. syntax &lsquo;<samp>mov al, byte ptr <var>foo</var></samp>&rsquo; is &lsquo;<samp>movb <var>foo</var>, %al</samp>&rsquo; in AT&amp;T
  134. syntax. In Intel syntax, &lsquo;<samp>fword ptr</samp>&rsquo;, &lsquo;<samp>tbyte ptr</samp>&rsquo; and
  135. &lsquo;<samp>oword ptr</samp>&rsquo; specify 48-bit, 80-bit and 128-bit memory references.
  136. <p>In 64-bit code, &lsquo;<samp>movabs</samp>&rsquo; can be used to encode the &lsquo;<samp>mov</samp>&rsquo;
  137. instruction with the 64-bit displacement or immediate operand.
  138. </p>
  139. </li><li> <a name="index-return-instructions_002c-i386"></a>
  140. <a name="index-i386-jump_002c-call_002c-return"></a>
  141. <a name="index-return-instructions_002c-x86_002d64"></a>
  142. <a name="index-x86_002d64-jump_002c-call_002c-return"></a>
  143. Immediate form long jumps and calls are
  144. &lsquo;<samp>lcall/ljmp $<var>section</var>, $<var>offset</var></samp>&rsquo; in AT&amp;T syntax; the
  145. Intel syntax is
  146. &lsquo;<samp>call/jmp far <var>section</var>:<var>offset</var></samp>&rsquo;. Also, the far return
  147. instruction
  148. is &lsquo;<samp>lret $<var>stack-adjust</var></samp>&rsquo; in AT&amp;T syntax; Intel syntax is
  149. &lsquo;<samp>ret far <var>stack-adjust</var></samp>&rsquo;.
  150. </li><li> <a name="index-sections_002c-i386"></a>
  151. <a name="index-i386-sections"></a>
  152. <a name="index-sections_002c-x86_002d64"></a>
  153. <a name="index-x86_002d64-sections"></a>
  154. The AT&amp;T assembler does not provide support for multiple section
  155. programs. Unix style systems expect all programs to be single sections.
  156. </li></ul>
  157. <hr>
  158. <div class="header">
  159. <p>
  160. Next: <a href="i386_002dChars.html#i386_002dChars" accesskey="n" rel="next">i386-Chars</a>, Up: <a href="i386_002dSyntax.html#i386_002dSyntax" accesskey="u" rel="up">i386-Syntax</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>
  161. </div>
  162. </body>
  163. </html>