NASM 2.05 based x86 Instruction Reference[ch328]
A.5.303 STOSB, STOSW, STOSD: Store Byte to String STOSB ; AA [8086] STOSW ; o16 AB [8086] STOSD ; o32 AB [386] STOSB stores the byte in AL at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI). The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit "a16" or "a32" prefix. Segment override prefixes have no effect for this instruction: the use of ES for the store to [DI] or [EDI] cannot be overridden. STOSW and STOSD work in the same way, but they store the word in AX or the doubleword in EAX instead of the byte in AL, and increment or decrement the addressing registers by 2 or 4 instead of 1. The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times. The REP alias REPE, as well as the differently-encoded REPNE, are both allowed as well. They behave in the same way as REP.