×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to copy one string to another?
2

How to copy one string to another?

How to copy one string to another?

(OP)
I need some help with string coping.  How to write 32 bit code and copy string1 (e.g. "I am a student")to an empty string2.  

RE: How to copy one string to another?

If you know the length of the string to copy all you need to do is use movsb.

cld
ES:DI      = place to copy to
DS:SI      = place copying from
CX          = # of characters to copy
REP movsb   = Repeat mov until CX = 0

Hope this helps you.

"It is the struggle itself that is most important. It does not matter that we will never reach our ultimate goal."

DataC5155

"...NO FATE..."

RE: How to copy one string to another?

For 32-bit code, assuming flat model, the above are:

edi = place to copy to
esi = place to copy from
ecx = length of string (in bytes)
REP MOVSB ;REPeat: MOVe a String by Bytes

or better yet:
edi = place to copy to
esi = place to copy from
ecx = length of string (in bytes)
;we'll be needing it later on
push ecx
;we will move the string by DWORDS so divide length
;(in bytes) by 4 to get length in DWORDS
shr ecx,2
rep movsd ; REPeat: MOVe a String by Dwords
;however any extra bytes that don't fit into a DWORD will
;not get copied yet, so copy them too...
pop ecx
and ecx,03h
;if there are no extra bytes to copy, leave.
cmp ecx,0
je exit
rep movsb ;copy extra bytes that don't fit into a dword

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: How to copy one string to another?

:) Show Off :)
You have to leave SOME of the work up to them.
But you got me on the E's. I missed the 32-Bit Part the first time I read the question.

DataC5155

"...NO FATE..."

RE: How to copy one string to another?



That's what I like about this forum... I can always show off to n00bs!!!

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close