AT& T汇编程序子串

时间:2018-04-24 18:25:12

标签: assembly x86 att

假设我在寄存器%edx中有一个字符串“Hello to everyone”,我想将“Hello to e”移动到%eax,这可能吗?如何? (字符串的地址是12(%ebp))。

1 个答案:

答案 0 :(得分:1)

  寄存器%edx

中的“大家好”

你实际上并没有“拥有”寄存器中的字符串。相反,你有记忆参考。

如果您不想截断原始字符串。你可以这样做

; Method #1: Copy the cut part of the string to a new address %edi
movl $10,%ecx   ; Store the length of cut string to %ecx
movl %edx,%esi  ; Copy the address of original string to %esi (Source Index)
rep movsb       ; This instruction copies %ecx bytes from %esi to %edi (Destination Index)
movb $0,(%edi)
movl %edi,%eax

如果您只想修改当前字符串

,请使用方法#2
; Method #2: Cut the current string
movb $0,10(%edx) ; Put a null-terminator at the end of letter 'e'
相关问题