LODS?/STOS? Command
These instructions either load in or store a byte or a word to or from
memory. The DS:SI register pair points to the source data. These are the
registers the CPU will use when reading from memory using the LODS? instruction.
The AX/AL register will hold the number to either read from or write to
the memory. So, if DS:SI points to a byte which is maybe 60, then a "LODSB"
instruction will load in the number 60 into the AL register.
A LODSB or STOSB
will use the AL register while the LODSW or
STOSW will use the AX register. The STOS writes
whatever is in the AX/AL register to the memory pointed to by ES:DI. If
ES:DI points to 100:102h and if AL held 50, then the byte at 100:102h will
hold 50. After the instruction is finished, the CPU will either increment
or decrement SI or DI according to the status of the direction flag. If
SI was 100h and a "LODSW" instruction was
performed with a cleared direction flag (forward), the SI will now point
to 102h.