LODSB loads the byte at DS:SI into AL and moves SI to the next byte: +1 when DF = 0, -1 when DF = 1. LODSW loads AX and steps by 2. No flags change, so it can sit between a compare and its jump. It is a one-byte replacement for MOV AL, [SI] / INC SI.
The source segment can be overridden (LODS BYTE PTR ES:[SI]), since the source of every string instruction is DS:SI by default. DI is not involved.
With STOS: process a string
LODS is almost never repeated: REP LODSB is legal but each load overwrites the last, leaving only the final element in AL. Its real use is in a loop, often paired with STOSB: load an element, change it in AL, store it at ES:DI. When SI and DI start at the same address the string is changed in place. The loop below turns a string into capitals.
CLDMOV SI, OFFSET TXT1MOV DI, SI ; write back in placeMOV CX, 5NEXT1:LODSB ; AL = [SI], SI + 1CMP AL, 'a'JB KEEP1CMP AL, 'z'JA KEEP1SUB AL, 20h ; lowercase to uppercaseKEEP1:STOSB ; [DI] = AL, DI + 1LOOP NEXT1MOV DX, OFFSET TXT1MOV AH, 09h ; DOS: print the string at DS:DXINT 21hTXT1 DB 'shout', 13, 10, '$'
A loop can also stop on content instead of a count: load, CMP AL, 0, JE out. LODSW reads two bytes at a time; the byte at the lower address lands in AL. With a table of words, LODSW walks it one entry per instruction.
Pitfalls: forgetting CLD; and expecting SI to still point at the element you just loaded. After LODSB going forward it is at SI - 1.