Load String Instructions 

The load string instructions are useful when it is required to process the elements of an array. They have one of the following forms:

LODS src_string
LODSB
LODSW
LODSD

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:

InstructionDescription
LODSB AL<-DS:[SI] ;
IF (DF=0)
SI=SI+1
ELSE
SI=SI-1
LODSW AX<-DS:[SI+1:SI] ;
IF (DF=0)
SI=SI+2
ELSE
SI=SI-2
LODSD EAX<-DS:[SI+3:SI] ;
IF (DF=0)
SI=SI+4
ELSE
SI=SI-4

The LODSB instruction

The 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 instruction

The 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 instruction

The 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.

Example: Convert all string characters to upper case using load and store string instructions.
	MOV SI, offset Array
	MOV DI, SI
	MOV CX, 100	; Array length
	MOV AX, DS
	MOV ES, AX
	CLD
Next:	LODSB
	OR AL, 20H	; convert to upper case
 	STOSB
	LOOP Next	

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.