STOS            Store String                         Flags: Not altered

STOS destination_string

Logic [ES:eDI] ← accumulator
if DF = 0
eDI ← eDI + n ; n = 1 for byte, 2 for word,
else ; 4 for dword (386+)
eDI ← eDI - n
endif

This instruction transfers the contents of the AL, AX, or EAX
register to the memory byte, word, or doubleword pointed to by
ES and the destination-index register (DI or EDI). After the
transfer is made, eDI is automatically incremented (if the
direction flag is cleared) or decremented (if the direction flag
is set), in preparation for storing the next element of the
string.

If the address-size attribute of STOS is 16 bits, DI is used for
the destination-index register; otherwise the the address size is
32 bits, and the EDI register will be used.

The destination segment must be addressable from the ES register;
it cannot be changed with a segment override.


Note: This instruction is always translated by the assembler
into STOSB, Store String Byte, STOSW, Store String
Word, or STOSD, Store String Dword, depending upon
whether destination refers to a string of bytes, words
or doublewords. In either case, you must explicitly
load the eDI register with the offset of the
destination string.

STOSB, STOSW, and STOSD are synonyms for the byte,
word, and doubleword STOS instructions that do not
require an operand. They are simpler to use but
provide no type or segment checking.


STOS is usually preceded with a REP prefix for a block fill of CX
or ECX bytes bytes, words, or doublewords.


Opcode Format
AA STOS m8 ; = STOSB
AB STOS m16 ; = STOSW
AB STOS m32 ; = STOSD


Length and timing
Variations Bytes 8088 186 286 386 486 Pentium
stosb 1 11 10 3 4 5 3 NP
stosw 1 15 10 3 4 5 3 NP
stosd 1 - - - 4 5 3 NP
rep stosb 2 9+10n 6+9n 4+3n 5+5n 7+4n* 3+n NP
rep stosw 2 9+14n 6+9n 4+3n 5+5n 7+4n* 3+n NP
rep stosd 2 - - - 5+5n 7+4n* 3+n NP

* = 5 if n=0, 13 if n=1
(n = count of bytes, words or dwords)