Logic [ES:eDI] ← [DS:eSI] if DF = 0 eSI ← eSI + n ; n = 1 for byte, 2 for word, eDI ← eDI + n ; 4 for dword (386+) else eSI ← eSI - n eDI ← eDI - n endif
MOVS copies the byte, word, or doubleword at DS:eSI to the byte, word, or doubleword at ES:eDI. After the transfer, eSI and eDI are incremented (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for copying the next element of the string. If the address-size attribute of MOVS is 16 bits, the SI and DI registers will be used as source and destination indices; if 32 bits, ESI and EDI will be used.
The source segment can be changed with a segment override, the destination segment cannot.
Note: This instruction is always translated by the assembler into MOVSB, Move String Byte, MOVSW, Move String Word, or MOVSD, Move String Dword, depending upon whether source refers to a string of bytes, words or doublewords. In either case, you must explicitly load the eSI and eDI registers with the offset of the source and destination strings.
MOVSB, MOVSW, and MOVSD are synonyms for the byte, word, and doubleword MOVS instructions that do not require any operands. They are simpler to use but provide no type or segment checking.
If the REP prefix modifies this instruction, the CPU moves the value of the source string element to the value of the destination string element. It then steps eSI and eDI in the direction indicated by DF by the indicated size, until either the REP condition is false or eCX counts to zero.
Example: dataseg src db "A string",0 dest db 9 dup (0) codeseg mov di,ds mov es,di assume ds:dgroup,es:dgroup mov di,offset dest mov si,offset src mov cx,9 cld rep movs [src],[dest] ; rep movsb ; ax register unchanged by MOVS