# An example of the MOVS instructions (递增传送字符串)
#
# MOVS 把字符串从一内存位置传送到另一个内存位置的简单途径。
# movsb : 8bit
# movsw : 16bit
# movsl : 32bit
#
# MOVS使用隐含的源和目标操作数。
# 隐含的源操作数是ESI寄存器,它指向源字符串的内存位置。 ESI(S)->source
# 隐含的目标操作数是EDI寄存器,它指向字符串要被复制到的目标内存位置。EDI(D)->destination
#
# 每次执行MOVS时,数据传送后,ESI和EDI寄存器会自动改变,为另一次传送做准备。但有时候这会变得有些难于处理。
# ESI和EDI自动传递增,也可能自动传递减,这取决于EFLAGS寄存器中的DF标志。
# DF清零, 增, DF被设置,减。
#
# CLD 用于将DF标志清零
# STD 用于设置DF标志
#
#
# 两种方式加载ESI、EDI值。
# 间接寻址:通过在内存位置标签前面添加美元符号,内存位置的地址被加载到ESI或EDI寄存器中
# movl $output, %ed # 把output标签的32位内存位置传送给EDI
#
# LEA:加载一个对象的有效地址。
# leal output, %edi
#
.section .data
value1:
.ascii "This is a test string.\n"
.section .bss
.lcomm output, 23
.section .text
.globl main
main:
nop
leal value1, %esi
leal output, %edi
movsb
movsw
movsl
movl $1, %eax
movl $0, %ebx
int $0x80
# gcc -g -o 01 01-movs.s -m32
#
# (gdb) b 31
# Breakpoint 1 at 0x119e: file 01-movs.s, line 31.
# (gdb) r
# Breakpoint 1, main () at 01-movs.s:31
# 31 leal value1, %esi
# (gdb) s
# 32 leal output, %edi
# (gdb) s
# 33 movsb
# (gdb) x/x &output
# 0x56559028 <output>: 0x00000000
# (gdb) x/s &output
# 0x56559028 <output>: ""
# (gdb) s
# 34 movsw
# (gdb) x/s &output
# 0x56559028 <output>: "T"
# (gdb) s
# 35 movsl
# (gdb) x/s &output
# 0x56559028 <output>: "Thi"
(gdb) s
# 37 movl $1, %eax
# (gdb) x/s &output
# 0x56559028 <output>: "This is"