View previous topic :: View next topic |
Author |
Message |
Freiza Grandmaster Cheater
Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Wed Apr 11, 2012 12:21 pm Post subject: how to copy string |
|
|
How to do this
Where is [ebx] is string[8]
I tried
mov byte ptr [ebx+0],'h'
mov byte ptr [ebx+1],'e'
mov byte ptr [ebx+2],'l'
mov byte ptr [ebx+3],'l'
mov byte ptr [ebx+4],'o'
mov byte ptr [ebx+5],0
but having problems also tried using hex values
_________________
|
|
Back to top |
|
 |
Kavvman Master Cheater
Reputation: 2
Joined: 17 Apr 2004 Posts: 316
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Apr 11, 2012 6:05 pm Post subject: |
|
|
Kavvman wrote: | use the ascii code to store each letter. something like this
mov byte ptr [ebx], 43h
You can also use the rep instruction to perform string operations...read more here
http://faydoc.tripod.com/cpu/rep.htm |
The rep instruction is useless in this case since he is not copying a string. Copying byte by byte is also wasteful and will result in slow and redundantly verbose code. A DWORD can be copied instead.
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25788 Location: The netherlands
|
Posted: Wed Apr 11, 2012 6:29 pm Post subject: |
|
|
Quote: |
mov byte ptr [ebx+0],'h'
mov byte ptr [ebx+1],'e'
mov byte ptr [ebx+2],'l'
mov byte ptr [ebx+3],'l'
mov byte ptr [ebx+4],'o'
mov byte ptr [ebx+5],0
|
works fine. What is the problem ?
rep is also an option:
Code: |
hellostr:
db 'hello',0
...
cld //clear the direction flag (else edi/esi might go backwards)
mov edi,ebx //set destination
mov esi,teststr //set origin
mov ecx,6 //set number of bytes to copy
rep movsb //repeat movsb ecx times
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
Kavvman Master Cheater
Reputation: 2
Joined: 17 Apr 2004 Posts: 316
|
Posted: Wed Apr 11, 2012 6:46 pm Post subject: |
|
|
Slugsnack wrote: | Kavvman wrote: | use the ascii code to store each letter. something like this
mov byte ptr [ebx], 43h
You can also use the rep instruction to perform string operations...read more here
http://faydoc.tripod.com/cpu/rep.htm |
The rep instruction is useless in this case since he is not copying a string. Copying byte by byte is also wasteful and will result in slow and redundantly verbose code. A DWORD can be copied instead. |
Keep your crap existence to the useless section.
The OP had trouble with strings operation, his thread title is "how to copy string". A helpful reply would be to show the different ways he can solve the problem and if he is copying a string the reps instruction is the best he can use. The thread isn't about performance anyway.
@DB: small correction
Quote: | hellostr:
db 'hello',0
...
cld //clear the direction flag (else edi/esi might go backwards)
mov edi,ebx //set destination
mov esi,teststr //set origin :> should be hellostr
mov ecx,6 //set number of bytes to copy
rep movsb //repeat movsb ecx times |
_________________
... |
|
Back to top |
|
 |
Freiza Grandmaster Cheater
Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Wed Apr 11, 2012 6:57 pm Post subject: |
|
|
Dark Byte wrote: | Quote: |
mov byte ptr [ebx+0],'h'
mov byte ptr [ebx+1],'e'
mov byte ptr [ebx+2],'l'
mov byte ptr [ebx+3],'l'
mov byte ptr [ebx+4],'o'
mov byte ptr [ebx+5],0
|
works fine. What is the problem ?
rep is also an option:
Code: |
hellostr:
db 'hello',0
...
cld //clear the direction flag (else edi/esi might go backwards)
mov edi,ebx //set destination
mov esi,teststr //set origin
mov ecx,6 //set number of bytes to copy
rep movsb //repeat movsb ecx times
|
|
yes that was not the problem. I messed up the pointers and you helped me out.
_________________
|
|
Back to top |
|
 |
|