<<< STD Set Direction Flag (DF)     Index     SUB Arithmetic Subtraction >>>


STOS Store String

Flags affected:

        O D I T S Z A P C  OF: Overflow flag  TF: Trap flag AF: Aux carry
        F F F F F F F F F  DF: Direction flag SF: Sign flag PF: Parity flag
            <none>         IF: Interrupt flag ZF: Zero flag CF: Carry flag

Legal forms:

        STOS ES:m8
        STOS ES:m16
        STOSB
        STOSW
        STOSD             386+

Examples:

        STOS ES:WordVar    ;Stores AX to [ES:DI]
        STOS ES:ByteVar    ;Stores AL to [ES:DI]
        STOSB              ;Stores AL to [ES:DI]
        STOSW              ;Stores AX to [ES:DI]
        STOSD              ;Stores EAX to [EDI]
        REP STOSW          ;Stores AX to [ES:DI] and up, for CX repeats

Notes:

Stores either AL (for 8-bit store operations), AX (for 16-bit operations), or EAX (for 32-bit operations) to the location at [ES:DI] or (for 32-bit operations) [EDI]. ES must be the segment of the destination and cannot be overridden. (For 32-bit protected mode flat model, all segments are congruent and thus ES does not need to be specified explicitly.) Similarly, DI or EDI must always be the destination offset.

By placing an operation repeat count (not a byte, word, or dword count!) in CX/ECX and preceding the mnemonic with the REP prefix, STOS can do an automatic "machine-gun" store of AL/AX/EAX into successive memory locations beginning at the initial [ES:DI] or [EDI]. After each store, DI/EDI is adjusted (see next paragraph) by either by 1 (for 8-bit store operations), 2 (for 16-bit store operations), or 4 (for 32-bit store operations), and CX is decremented by 1. Don't forget that CX/ECX counts operations (the number of times a data item is stored to memory) and not bytes!

Adjusting means incrementing if the Direction flag is cleared (by CLD) or decrementing if the Direction flag has been set.

        r8 = AL AH BL BH CL CH DL DH        r16 = AX BX CX DX BP SP SI DI
        sr = CS DS SS ES FS GS              r32 = EAX EBX ECX EDX EBP ESP ESI EDI
        m8 = 8-bit memory data              m16 = 16-bit memory data
        m32 = 32-bit memory data            i8 = 8-bit immediate data
        i16 = 16-bit immediate data         i32 = 32-bit immediate data
        d8 = 8-bit signed displacement      d16 = 16-bit signed displacement
        d32 = 32-bit unsigned displacement


<<< STD Set Direction Flag (DF)     Index     SUB Arithmetic Subtraction >>>