Storing and Loading Strings

来源:互联网 发布:redis可视化工具 知乎 编辑:程序博客网 时间:2024/05/15 22:39
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.

 When the STOS instruction is executed, it will either increment or decrement the EDI register value by the data size used.

.section .dataspace:.ascii “ “.section .bss.lcomm buffer, 256.section .text.globl _start_start:nopleal space, %esileal buffer, %edimovl $256, %ecxcldlodsbrep stosbmovl $1, %eaxmovl $0, %int $0x80


原创粉丝点击