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