Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy one string to another? 2

Status
Not open for further replies.

zorica

Programmer
Oct 12, 2002
1
0
0
US
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.
 
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..."
 
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."
 
:) 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..."
 
:p

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."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top