| |||||||||||||||||||
| |||||||||||||||||||
The load string instructions are useful when it is required to process the elements of an array. They have one of the following forms:
The LODS instruction only requires a source string (pointed at by DS:SI). The destination operand is the AL (LODSB), AX (LODSW), or EAX (LODSD) register. The LODS instruction loads the value from the corresponding locations pointed by DS:SI into the accumulator (AL, AX, or EAX) and then increments (or decrements) SI by one, two, or four. When the first form, LODS src_string, is used the assembler will replace it by LODSB, LODSW, or LODSD depending on the size of the operand src_string. The semantics of the instructions LODSB, LODSW, and LODSD is illustrated below:
The LODSB instructionThe LODSB loads the byte addressed by DS:[SI] into register AL. SI is then incremented (if DF=0) or decremented (if DF=1) by 1. The LODSW instructionThe LODSW loads the word addressed by DS:[SI] into register AX. SI is then incremented (if DF=0) or decremented (if DF=1) by 2. The LODSD instructionThe LODSD loads the double word addressed by DS:[SI] into register EAX. SI is then incremented (if DF=0) or decremented (if DF=1) by 4. Note that repeat prefixes cannot be used with load string instructions as their use does not make sense. The next example illustrates the use of the load and store string instructions in converting the characters of strings to upper case characters.
Note that since the character is already an upper case, it will remain upper case by the instruction OR AL, 20H. However, the lower case characters will be converted to upper case characters. Also, note that since the blank character has the ASCII code 20H, it will not be affected and will remain as is.
|