You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 line
6.5KB

  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 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>i386-16bit (Using as)</title>
  16. <meta name="description" content="i386-16bit (Using as)">
  17. <meta name="keywords" content="i386-16bit (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  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_002dDependent.html#i386_002dDependent" rel="up" title="i386-Dependent">
  25. <link href="i386_002dArch.html#i386_002dArch" rel="next" title="i386-Arch">
  26. <link href="i386_002dTBM.html#i386_002dTBM" rel="prev" title="i386-TBM">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="i386_002d16bit"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="i386_002dArch.html#i386_002dArch" accesskey="n" rel="next">i386-Arch</a>, Previous: <a href="i386_002dTBM.html#i386_002dTBM" accesskey="p" rel="prev">i386-TBM</a>, Up: <a href="i386_002dDependent.html#i386_002dDependent" accesskey="u" rel="up">i386-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>
  60. </div>
  61. <hr>
  62. <a name="Writing-16_002dbit-Code"></a>
  63. <h4 class="subsection">9.16.14 Writing 16-bit Code</h4>
  64. <a name="index-i386-16_002dbit-code"></a>
  65. <a name="index-16_002dbit-code_002c-i386"></a>
  66. <a name="index-real_002dmode-code_002c-i386"></a>
  67. <a name="index-code16gcc-directive_002c-i386"></a>
  68. <a name="index-code16-directive_002c-i386"></a>
  69. <a name="index-code32-directive_002c-i386"></a>
  70. <a name="index-code64-directive_002c-i386"></a>
  71. <a name="index-code64-directive_002c-x86_002d64"></a>
  72. <p>While <code>as</code> normally writes only &ldquo;pure&rdquo; 32-bit i386 code
  73. or 64-bit x86-64 code depending on the default configuration,
  74. it also supports writing code to run in real mode or in 16-bit protected
  75. mode code segments. To do this, put a &lsquo;<samp>.code16</samp>&rsquo; or
  76. &lsquo;<samp>.code16gcc</samp>&rsquo; directive before the assembly language instructions to
  77. be run in 16-bit mode. You can switch <code>as</code> to writing
  78. 32-bit code with the &lsquo;<samp>.code32</samp>&rsquo; directive or 64-bit code with the
  79. &lsquo;<samp>.code64</samp>&rsquo; directive.
  80. </p>
  81. <p>&lsquo;<samp>.code16gcc</samp>&rsquo; provides experimental support for generating 16-bit
  82. code from gcc, and differs from &lsquo;<samp>.code16</samp>&rsquo; in that &lsquo;<samp>call</samp>&rsquo;,
  83. &lsquo;<samp>ret</samp>&rsquo;, &lsquo;<samp>enter</samp>&rsquo;, &lsquo;<samp>leave</samp>&rsquo;, &lsquo;<samp>push</samp>&rsquo;, &lsquo;<samp>pop</samp>&rsquo;,
  84. &lsquo;<samp>pusha</samp>&rsquo;, &lsquo;<samp>popa</samp>&rsquo;, &lsquo;<samp>pushf</samp>&rsquo;, and &lsquo;<samp>popf</samp>&rsquo; instructions
  85. default to 32-bit size. This is so that the stack pointer is
  86. manipulated in the same way over function calls, allowing access to
  87. function parameters at the same stack offsets as in 32-bit mode.
  88. &lsquo;<samp>.code16gcc</samp>&rsquo; also automatically adds address size prefixes where
  89. necessary to use the 32-bit addressing modes that gcc generates.
  90. </p>
  91. <p>The code which <code>as</code> generates in 16-bit mode will not
  92. necessarily run on a 16-bit pre-80386 processor. To write code that
  93. runs on such a processor, you must refrain from using <em>any</em> 32-bit
  94. constructs which require <code>as</code> to output address or operand
  95. size prefixes.
  96. </p>
  97. <p>Note that writing 16-bit code instructions by explicitly specifying a
  98. prefix or an instruction mnemonic suffix within a 32-bit code section
  99. generates different machine instructions than those generated for a
  100. 16-bit code segment. In a 32-bit code section, the following code
  101. generates the machine opcode bytes &lsquo;<samp>66 6a 04</samp>&rsquo;, which pushes the
  102. value &lsquo;<samp>4</samp>&rsquo; onto the stack, decrementing &lsquo;<samp>%esp</samp>&rsquo; by 2.
  103. </p>
  104. <div class="smallexample">
  105. <pre class="smallexample"> pushw $4
  106. </pre></div>
  107. <p>The same code in a 16-bit code section would generate the machine
  108. opcode bytes &lsquo;<samp>6a 04</samp>&rsquo; (i.e., without the operand size prefix), which
  109. is correct since the processor default operand size is assumed to be 16
  110. bits in a 16-bit code section.
  111. </p>
  112. <hr>
  113. <div class="header">
  114. <p>
  115. Next: <a href="i386_002dArch.html#i386_002dArch" accesskey="n" rel="next">i386-Arch</a>, Previous: <a href="i386_002dTBM.html#i386_002dTBM" accesskey="p" rel="prev">i386-TBM</a>, Up: <a href="i386_002dDependent.html#i386_002dDependent" accesskey="u" rel="up">i386-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>
  116. </div>
  117. </body>
  118. </html>