📄 i386-16bit.html
字号:
<html lang="en">
<head>
<title>Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
</head>
<body>
<div class="node">
<p>
Node:<a name="i386-16bit">i386-16bit</a>,
Next:<a rel="next" accesskey="n" href="i386-Arch.html#i386-Arch">i386-Arch</a>,
Previous:<a rel="previous" accesskey="p" href="i386-SIMD.html#i386-SIMD">i386-SIMD</a>,
Up:<a rel="up" accesskey="u" href="i386-Dependent.html#i386-Dependent">i386-Dependent</a>
<hr><br>
</div>
<h4 class="section">Writing 16-bit Code</h4>
<p>While <code>as</code> normally writes only "pure" 32-bit i386 code
or 64-bit x86-64 code depending on the default configuration,
it also supports writing code to run in real mode or in 16-bit protected
mode code segments. To do this, put a <code>.code16</code> or
<code>.code16gcc</code> directive before the assembly language instructions to
be run in 16-bit mode. You can switch <code>as</code> back to writing
normal 32-bit code with the <code>.code32</code> directive.
<p><code>.code16gcc</code> provides experimental support for generating 16-bit
code from gcc, and differs from <code>.code16</code> in that <code>call</code>,
<code>ret</code>, <code>enter</code>, <code>leave</code>, <code>push</code>, <code>pop</code>,
<code>pusha</code>, <code>popa</code>, <code>pushf</code>, and <code>popf</code> instructions
default to 32-bit size. This is so that the stack pointer is
manipulated in the same way over function calls, allowing access to
function parameters at the same stack offsets as in 32-bit mode.
<code>.code16gcc</code> also automatically adds address size prefixes where
necessary to use the 32-bit addressing modes that gcc generates.
<p>The code which <code>as</code> generates in 16-bit mode will not
necessarily run on a 16-bit pre-80386 processor. To write code that
runs on such a processor, you must refrain from using <em>any</em> 32-bit
constructs which require <code>as</code> to output address or operand
size prefixes.
<p>Note that writing 16-bit code instructions by explicitly specifying a
prefix or an instruction mnemonic suffix within a 32-bit code section
generates different machine instructions than those generated for a
16-bit code segment. In a 32-bit code section, the following code
generates the machine opcode bytes <code>66 6a 04</code>, which pushes the
value <code>4</code> onto the stack, decrementing <code>%esp</code> by 2.
<pre class="smallexample"> pushw $4
</pre>
<p>The same code in a 16-bit code section would generate the machine
opcode bytes <code>6a 04</code> (ie. without the operand size prefix), which
is correct since the processor default operand size is assumed to be 16
bits in a 16-bit code section.
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -