70 lines
10 KiB
HTML
70 lines
10 KiB
HTML
<html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
|
<html>
|
|
|
|
<head>
|
|
<title>80386 Programmer's Reference Manual -- Section 3.1</title>
|
|
</head>
|
|
|
|
<body>
|
|
<b>up:</b> <a href="C03.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C03.HTM">Chapter 3 -- Applications Instruction Set</a><br>
|
|
<b>prev:</b> <a href="C03.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C03.HTM">Chapter 3 -- Applications Instruction Set</a><br>
|
|
<b>next:</b> <a href="S03_02.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/S03_02.HTM">3.2 Binary Arithmetic Instructions</a>
|
|
<p>
|
|
<hr>
|
|
<p>
|
|
<h1>3.1 Data Movement Instructions</h1>
|
|
These instructions provide convenient methods for moving bytes, words, or doublewords of data between memory and the registers of the base architecture. They fall into the following classes:
|
|
<ol>
|
|
<li>General-purpose data movement instructions.
|
|
<li>Stack manipulation instructions.
|
|
<li>Type-conversion instructions.
|
|
</ol>
|
|
<h2>3.1.1 General-Purpose Data Movement Instructions</h2>
|
|
<a href="MOV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOV.HTM">MOV</a> (Move) transfers a byte, word, or doubleword from the source operand to the destination operand. The <a href="MOV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOV.HTM">MOV</a> instruction is useful for transferring data along any of these paths There are also variants of <a href="MOV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOV.HTM">MOV</a> that operate on segment registers. These are covered in a later section of this chapter:
|
|
<ul>
|
|
<li>To a register from memory
|
|
<li>To memory from a register
|
|
<li>Between general registers
|
|
<li>Immediate data to a register
|
|
<li>Immediate data to a memory
|
|
</ul>
|
|
The <a href="MOV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOV.HTM">MOV</a> instruction cannot move from memory to memory or from segment register to segment register are not allowed. Memory-to-memory moves can be performed, however, by the string move instruction <a href="MOVS.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOVS.HTM">MOVS</a>.
|
|
<p><a href="XCHG.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/XCHG.HTM">XCHG</a> (Exchange) swaps the contents of two operands. This instruction takes the place of three <a href="MOV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOV.HTM">MOV</a> instructions. It does not require a temporary location to save the contents of one operand while load the other is being loaded. <a href="XCHG.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/XCHG.HTM">XCHG</a> is especially useful for implementing semaphores or similar data structures for process synchronization.
|
|
<p>The <a href="XCHG.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/XCHG.HTM">XCHG</a> instruction can swap two byte operands, two word operands, or two doubleword operands. The operands for the <a href="XCHG.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/XCHG.HTM">XCHG</a> instruction may be two register operands, or a register operand with a memory operand. When used with a memory operand, <a href="XCHG.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/XCHG.HTM">XCHG</a> automatically activates the <a href="LOCK.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/LOCK.HTM">LOCK</a> signal. (Refer to <a href="C11.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C11.HTM">Chapter 11</a> for more information on the bus lock. )
|
|
<h2>3.1.2 Stack Manipulation Instructions</h2>
|
|
<a href="PUSH.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSH.HTM">PUSH</a> (Push) decrements the stack pointer (ESP), then transfers the source operand to the top of stack indicated by ESP (see <a href="#fig3-1">Figure 3-1</a>). <a href="PUSH.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSH.HTM">PUSH</a> is often used to place parameters on the stack before calling a procedure; it is also the basic means of storing temporary variables on the stack. The <a href="PUSH.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSH.HTM">PUSH</a> instruction operates on memory operands, immediate operands, and register operands (including segment registers).
|
|
<p><a href="PUSHA.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSHA.HTM">PUSHA</a> (Push All Registers) saves the contents of the eight general registers on the stack (see <a href="#fig3-2">Figure 3-2</a>). This instruction simplifies procedure calls by reducing the number of instructions required to retain the contents of the general registers for use in a procedure. The processor pushes the general registers on the stack in the following order: EAX, ECX, EDX, EBX, the initial value of ESP before EAX was pushed, EBP, ESI, and EDI. <a href="PUSHA.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSHA.HTM">PUSHA</a> is complemented by the <a href="POPA.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/POPA.HTM">POPA</a> instruction.
|
|
<p><a href="POP.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/POP.HTM">POP</a> (Pop) transfers the word or doubleword at the current top of stack (indicated by ESP) to the destination operand, and then increments ESP to point to the new top of stack. See <a href="#fig3-3">Figure 3-3</a>. <a href="POP.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/POP.HTM">POP</a> moves information from the stack to a general register, or to memory There are also a variant of <a href="POP.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/POP.HTM">POP</a> that operates on segment registers. This is covered in a later section of this chapter.
|
|
<p><a href="POPA.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/POPA.HTM">POPA</a> (Pop All Registers) restores the registers saved on the stack by <a href="PUSHA.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/PUSHA.HTM">PUSHA</a>, except that it ignores the saved value of ESP. See <a href="#fig3-4">Figure 3-4</a>.
|
|
<p><a name="fig3-1"><img align="center" src="FIG3-1.GIF" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/FIG3-1.GIF" border="0">
|
|
<p>
|
|
<hr>
|
|
<p><a name="fig3-2"><img align="center" src="FIG3-2.GIF" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/FIG3-2.GIF" border="0">
|
|
<p>
|
|
<h2>3.1.3 Type Conversion Instructions</h2>
|
|
The type conversion instructions convert bytes into words, words into doublewords, and doublewords into 64-bit items (quad-words). These instructions are especially useful for converting signed integers, because they automatically fill the extra bits of the larger item with the value of the sign bit of the smaller item. This kind of conversion, illustrated by <a href="#fig3-5">Figure 3-5</a>, is called sign extension.
|
|
<p>There are two classes of type conversion instructions:
|
|
<ol>
|
|
<li>The forms <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CWD</a>, <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CDQ</a>, <a href="CBW.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CBW.HTM">CBW</a>, and <a href="CBW.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CBW.HTM">CWDE</a> which operate only on data in the EAX register.
|
|
<li>The forms <a href="MOVSX.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOVSX.HTM">MOVSX</a> and <a href="MOVZX.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOVZX.HTM">MOVZX</a>, which permit one operand to be in any general register while permitting the other operand to be in memory or in a register.
|
|
</ol>
|
|
<a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CWD</a> (Convert Word to Doubleword) and <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CDQ</a> (Convert Doubleword to Quad-Word) double the size of the source operand. <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CWD</a> extends the sign of the word in register AX throughout register DX. <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CDQ</a> extends the sign of the doubleword in EAX throughout EDX. <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CWD</a> can be used to produce a doubleword dividend from a word before a word division, and <a href="CWD.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CWD.HTM">CDQ</a> can be used to produce a quad-word dividend from a doubleword before doubleword division.
|
|
<p><a href="CBW.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CBW.HTM">CBW</a> (Convert Byte to Word) extends the sign of the byte in register AL throughout AX.
|
|
<p><a href="CBW.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/CBW.HTM">CWDE</a> (Convert Word to Doubleword Extended) extends the sign of the word in register AX throughout EAX.
|
|
<p><a href="MOVSX.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOVSX.HTM">MOVSX</a> (Move with Sign Extension) sign-extends an 8-bit value to a 16-bit value and a 8- or 16-bit value to 32-bit value.
|
|
<p><a href="MOVZX.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/MOVZX.HTM">MOVZX</a> (Move with Zero Extension) extends an 8-bit value to a 16-bit value and an 8- or 16-bit value to 32-bit value by inserting high-order zeros.
|
|
<p><a name="fig3-3"><img align="center" src="FIG3-3.GIF" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/FIG3-3.GIF" border="0">
|
|
<p>
|
|
<hr>
|
|
<p><a name="fig3-4"><img align="center" src="FIG3-4.GIF" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/FIG3-4.GIF" border="0">
|
|
<p>
|
|
<hr>
|
|
<p><a name="fig3-5"><img align="center" src="FIG3-5.GIF" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/FIG3-5.GIF" border="0">
|
|
<p>
|
|
<hr>
|
|
<p><b>up:</b> <a href="C03.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C03.HTM">Chapter 3 -- Applications Instruction Set</a><br>
|
|
<b>prev:</b> <a href="C03.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C03.HTM">Chapter 3 -- Applications Instruction Set</a><br>
|
|
<b>next:</b> <a href="S03_02.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/S03_02.HTM">3.2 Binary Arithmetic Instructions</a>
|
|
</body>
|
|
|