Reputation: 75
Say I have a string "Hello to everyone" in register %edx, and I want to move "Hello to e" to %eax, is this possible? And how? (Address to the string is in 12(%ebp)).
Upvotes: 0
Views: 390
Reputation: 302
"Hello to everyone" in register %edx
You don't actually "have" the string in a register. Instead, you have memory reference to it.
If you do not want to truncate the original string. You can do this
; 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
Use method #2 if you only want to modify the current string
; Method #2: Cut the current string
movb $0,10(%edx) ; Put a null-terminator at the end of letter 'e'
Upvotes: 1