any way to copy a string buffers contents to another using a api call?
Posted on 2002-04-30 16:30:59 by Qages
mov ecx,NumberOfBytesOfString
mov esi,Buffer1
mov edi,Buffer2
rep movsb
Posted on 2002-04-30 16:47:14 by CodeLover
kernel32!lstrcpy if you want to use an api, but be warned that it's
quite slow.
Posted on 2002-04-30 16:59:15 by f0dder
memcpy :)

hmm a Mewtwo on the forum! :grin:
Posted on 2002-04-30 17:19:52 by stryker
Posted on 2002-04-30 17:54:36 by Qages
This is what i uses, (pieces from M32.lib ... lighting no API needed

mov esi,Buffer1
mov edi,Buffer2
mov ecx, SIZEOF Buffer1
rep movsb

if you know the size ALWAYS do this
mov esi,Buffer1
mov edi,Buffer2
mov ecx, 42
rep movsb
Posted on 2002-06-29 17:18:59 by cmax
Afternoon, Qages.

If the original buffer is zero-terminated (i.e. it's a zero-terminated string), then you try this "highly-optimized" way:
invoke wsprintf, ADDR buffer_new, CTEXT("%s"), ADDR buffer_orig

Posted on 2002-06-29 20:17:41 by Scronty
Scronty , is this the way to go... If so i got to do some gutting TONIGHT...but how could it possibly be faster or even equal to raw coding with rep movsb
Posted on 2002-06-29 20:32:33 by cmax
Afternoon, cmax.

The quotemarks around "highly-optimized", and the :grin: icon, are to indicate that I'm only joking :tongue: .

The MemCopy in the Masm32.lib file will do the job fine ( \masm32\M32LIB\MEMCOPY.ASM).

Also, there's this one, which is a modified MemCopy:

;-- MemCopyN --------------------------------------------------------------
;-- Copy ln bytes of memory from Source buffer to Dest buffer -------------
;-- beginning at startat position in Dest buffer. -------------------------
;-- Source == pointer to source buffer -----------------------------------
;-- Dest == pointer to destination buffer ------------------------------
;-- startat == start offset into destination buffer -----------------------
;-- ln == number of bytes to copy ------------------------------------
MemCopyN proc public uses esi edi Source:DWORD, Dest:DWORD, startat:DWORD, ln:DWORD

mov esi, [Source]
mov edi, [Dest]
mov eax, startat
add edi, eax
mov ecx, [ln]

shr ecx, 2
rep movsd

mov ecx, [ln]
and ecx, 3
rep movsb


MemCopyN endp

I use MemCopyN to append data to a buffer which isn't zero-terminated.

Posted on 2002-06-29 20:43:42 by Scronty
I though i must have miss something...You fool the heck out of ME... I was ALL gun hoe...

But ? why do all of that when what's above do it for you in 4 lines of code and you never have to use eax

I got it from M32 or one of Hutch Post Reply and it never fail...Posted on 2002-06-29 21:14:59 by cmax
Use scronty's code above, it's much more flexible than my code. Anyway, I'll just slapped this byte scanner/copier I did months ago to anyone who wants it.
MemCpy PROC USES ebx esi edi srcMem:DWORD, dstMem:DWORD, bytCopy:DWORD

mov esi, srcMem
mov edi, dstMem
mov edx, bytCopy
xor ecx, ecx


mov al, BYTE PTR [esi+ecx]
mov BYTE PTR [edi+ecx], al
inc ecx
cmp ecx, edx
jne @@CopyMem


srcMem - source memory. Must be a pointer in memory
dstMem - destination memory. Must be a pointer in memory.
bytCopy - n bytes to copy.

Want to use faster versions? Check these MemCpy here

Posted on 2002-06-29 21:19:15 by stryker
cmax, just because something is only a few instructions doesn't
mean it's necessarily faster than a longer piece of code... think
about all the "MMX madness" that svin and bitrake have been
doing, there's certainly a lot of instructions there... but those routines
tend to be faster than other routines with just "a few" instructions :).
Posted on 2002-06-30 09:42:07 by f0dder
lol, this is an old post. i have solved it. i made a complex FPU copying, its a bit slow, only becuase its extreemly accurate. i mean if you want it to copy 82 bytes, it will do 10 loops of 8 and then 2 loops of 1. however if i wanted i could have it just copy all 8's. but when i usualy copy,its borderd by data that i dont want or cant be copyed(like unallocated memory)
Posted on 2002-06-30 13:16:53 by Qages