Assembly AT&T汇编程序子串

Assembly AT&T汇编程序子串,assembly,x86,att,Assembly,X86,Att,假设我有一个字符串“Hello to everyone in register%edx”,我想将Hello to e移动到%eax,这可能吗?怎么做?字符串的地址位于12%ebp中 您好,注册表%edx中的所有人 实际上,寄存器中没有字符串。相反,您有对它的内存引用 如果不想截断原始字符串。你可以这样做 ; Method #1: Copy the cut part of the string to a new address %edi movl $10,%ecx ; Store the le

假设我有一个字符串“Hello to everyone in register%edx”,我想将Hello to e移动到%eax,这可能吗?怎么做?字符串的地址位于12%ebp中

您好,注册表%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'

不可能。edx中没有该字符串,但有指向该字符串的指针。除非你在复制后终止它,否则它不会神奇地变短。好吧,你的意思是,如果我有一个特定的索引,我想在这个例子中,比如说10,那么我可以和那个0x0的字节一起,把它调零,从而能够缩短它?如果在字符串中间插入一个零字节,则可以有效地截断它。但请确保它是可写的。您的第一个代码段不会终止复制的字符串,并且rep movsb之后的mov%edi,%eax会给您一个指向复制结束的指针。您的第二个版本可能应该使用movb只存储一个终止的0字节。@PeterCordes-Oops。我的AT&T汇编不如英特尔汇编好