Besides moving strings from one memory location to another, there are also instructions for loading string values in memory into registers, and then back into memory locations.
This section describes the STOS and LODS instructions that are used for this purpose.
The LODS instruction
The LODS instruction is used to move a string value in memory into the EAX register
LODSB: Loads a byte into the AL register
LODSW: Loads a word (2 bytes) into the AX register
LODSL: Loads a doubleword (4 bytes) into the EAX register
The LODS instructions use an implied source operand of the ESI register.
The ESI register must contain the memory address of the location of the string to load.
The LODS instruction increments or decrements (depending on the DF flag status) the ESI register by the amount of data loaded after the data is moved.
The STOS instruction
After the LODS instruction is used to place a string value in the EAX register, the STOS instruction can be used to place it in another memory location.
❑ STOSB: Stores a byte of data from the AL register
❑ STOSW: Stores a word (2 bytes) of data from the AX register
❑ STOSL: Stores a doubleword (4 bytes) of data from the EAX register
The STOS instruction uses an implied destination operand of the EDI register.
This section describes the STOS and LODS instructions that are used for this purpose.
The LODS instruction
The LODS instruction is used to move a string value in memory into the EAX register
LODSB: Loads a byte into the AL register
LODSW: Loads a word (2 bytes) into the AX register
LODSL: Loads a doubleword (4 bytes) into the EAX register
The LODS instructions use an implied source operand of the ESI register.
The ESI register must contain the memory address of the location of the string to load.
The LODS instruction increments or decrements (depending on the DF flag status) the ESI register by the amount of data loaded after the data is moved.
The STOS instruction
After the LODS instruction is used to place a string value in the EAX register, the STOS instruction can be used to place it in another memory location.
❑ STOSB: Stores a byte of data from the AL register
❑ STOSW: Stores a word (2 bytes) of data from the AX register
❑ STOSL: Stores a doubleword (4 bytes) of data from the EAX register
The STOS instruction uses an implied destination operand of the EDI register.
When the STOS instruction is executed, it will either increment or decrement the EDI register value by the data size used.
.section .data
space:
.ascii “ “
.section .bss
.lcomm buffer, 256
.section .text
.globl _start
_start:
nop
leal space, %esi
leal buffer, %edi
movl $256, %ecx
cld
lodsb
rep stosb
movl $1, %eax
movl $0, %
int $0x80