* better
[mascara-docs.git] / hw / i386.reference / MOVS.htm
blobe0b4087b87b37e94fa11928bb9de2bff2732a10d
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>80386 Programmer's Reference Manual -- Opcode MOVS</TITLE>
5 </HEAD>
6 <BODY>
7 <B>up:</B> <A HREF="c17.htm">
8 Chapter 17 -- 80386 Instruction Set</A><BR>
9 <B>prev:</B><A HREF="MOVRS.htm"> MOV Move to/from Special Registers</A><BR>
10 <B>next:</B><A HREF="MOVSX.htm"> MOVSX Move with Sign-Extend</A>
11 <P>
12 <HR>
13 <P>
14 <H1>MOVS/MOVSB/MOVSW/MOVSD -- Move Data from String to String</H1>
16 <PRE>
17 Opcode Instruction Clocks Description
19 A4 MOVS m8,m8 7 Move byte [(E)SI] to ES:[(E)DI]
20 A5 MOVS m16,m16 7 Move word [(E)SI] to ES:[(E)DI]
21 A5 MOVS m32,m32 7 Move dword [(E)SI] to ES:[(E)DI]
22 A4 MOVSB 7 Move byte DS:[(E)SI] to ES:[(E)DI]
23 A5 MOVSW 7 Move word DS:[(E)SI] to ES:[(E)DI]
24 A5 MOVSD 7 Move dword DS:[(E)SI] to ES:[(E)DI]
25 </PRE>
27 <H2>Operation</H2>
29 <PRE>
30 IF (instruction = MOVSD) OR (instruction has doubleword operands)
31 THEN OperandSize := 32;
32 ELSE OperandSize := 16;
33 IF AddressSize = 16
34 THEN use SI for source-index and DI for destination-index;
35 ELSE (* AddressSize = 32 *)
36 use ESI for source-index and EDI for destination-index;
37 FI;
38 IF byte type of instruction
39 THEN
40 [destination-index] := [source-index]; (* byte assignment *)
41 IF DF = 0 THEN IncDec := 1 ELSE IncDec := -1; FI;
42 ELSE
43 IF OperandSize = 16
44 THEN
45 [destination-index] := [source-index]; (* word assignment *)
46 IF DF = 0 THEN IncDec := 2 ELSE IncDec := -2; FI;
47 ELSE (* OperandSize = 32 *)
48 [destination-index] := [source-index]; (* doubleword assignment *)
49 IF DF = 0 THEN IncDec := 4 ELSE IncDec := -4; FI;
50 FI;
51 FI;
52 source-index := source-index + IncDec;
53 destination-index := destination-index + IncDec;
54 </PRE>
56 <H2>Description</H2>
58 MOVS copies the byte or word at [(E)SI] to the byte or word at
59 ES:[(E)DI]. The destination operand must be addressable from the ES
60 register; no segment override is possible for the destination. A segment
61 override can be used for the source operand; the default is DS.
62 <P>
63 The addresses of the source and destination are determined solely by the
64 contents of (E)SI and (E)DI. Load the correct index values into (E)SI
65 and (E)DI before executing the MOVS instruction. MOVSB, MOVSW,
66 and MOVSD are synonyms for the byte, word, and doubleword MOVS
67 instructions.
68 <P>
69 After the data is moved, both (E)SI and (E)DI are advanced
70 automatically. If the direction flag is 0 (<A HREF="CLD.htm">CLD</A> was executed), the registers
71 are incremented; if the direction flag is 1 (<A HREF="STD.htm">STD</A> was executed), the
72 registers are decremented. The registers are incremented or decremented by 1
73 if a byte was moved, 2 if a word was moved, or 4 if a doubleword was moved.
74 <P>
75 MOVS can be preceded by the
76 <A HREF="REP.htm">REP</A> prefix for block movement of CX
77 bytes or words. Refer to the
78 <A HREF="REP.htm">REP</A> instruction for details of this operation.
80 <H2>Flags Affected</H2>
82 None
84 <H2>Protected Mode Exceptions</H2>
86 #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
87 memory operand effective address in the CS, DS, ES, FS, or GS
88 segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
89 for a page fault
91 <H2>Real Address Mode Exceptions</H2>
93 Interrupt 13 if any part of the operand would lie outside of the effective
94 address space from 0 to 0FFFFH
96 <H2>Virtual 8086 Mode Exceptions</H2>
98 Same exceptions as in Real Address Mode; #PF(fault-code) for a page
99 fault
101 <HR>
103 <B>up:</B> <A HREF="c17.htm">
104 Chapter 17 -- 80386 Instruction Set</A><BR>
105 <B>prev:</B><A HREF="MOVRS.htm"> MOV Move to/from Special Registers</A><BR>
106 <B>next:</B><A HREF="MOVSX.htm"> MOVSX Move with Sign-Extend</A>
107 </BODY>