| |||||||||||||||||||
| |||||||||||||||||||
The store string instructions are useful in initializing a block of memory with a particular value. They have one of the following forms:
The STOS instruction only requires a destination string (pointed at by ES:DI). The source operand is the value in the AL (STOS), AX (STOSW), or EAX (STOSD) register. The STOS instruction stores the value in the accumulator (AL, AX, or EAX) into the corresponding locations pointed by ES:DI and then increments (or decrements) DI by one, two, or four. When the first form, STOS des_string, is used the assembler will replace it by STOSB, STOSW, or STOSD depending on the size of the operand dest_string. The semantics of the instructions STOSB, STOSW, and STOSD are illustrated below:
The STOSB instructionThe STOSB stores the value in the AL register into the byte addressed by ES:[DI]. DI is then incremented (if DF=0) or decremented (if DF=1) by 1. The STOSW instructionThe STOSW instruction stores the AX register into the word addressed by ES:[DI]. DI is then incremented (if DF=0) or decremented (if DF=1) by 2. The STOSD instructionThe STOSD instruction stores the EAX register into the double word addressed by ES:[DI]. DI is then incremented (if DF=0) or decremented (if DF=1) by 4. Note that it is possible to use only the unconditional repeat prefix REP with store string instructions. The next example illustrates the use of the store string instructions in initializing a block of memory by a particular value.
Note that we can initialize the Array using the dup operator by using the following declaration in the data segment: Array DB 100 DUP(-1) However, in many programming instances it is required to initialize an array repeatedly and in this case the store string instructions can be used.
|