any way to copy a string buffers contents to another using a api call?
mov ecx,NumberOfBytesOfString
mov esi,Buffer1
mov edi,Buffer2
rep movsb
mov esi,Buffer1
mov edi,Buffer2
rep movsb
kernel32!lstrcpy if you want to use an api, but be warned that it's
quite slow.
quite slow.
memcpy :)
hmm a Mewtwo on the forum! :grin:
hmm a Mewtwo on the forum! :grin:
:)
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
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
Afternoon, Qages.
If the original buffer is zero-terminated (i.e. it's a zero-terminated string), then you try this "highly-optimized" way:
Cheers,
Scronty
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
:grin:
Cheers,
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
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:
I use MemCopyN to append data to a buffer which isn't zero-terminated.
Cheers,
Scronty
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
cld
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
ret
MemCopyN endp
I use MemCopyN to append data to a buffer which isn't zero-terminated.
Cheers,
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
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.
dstMem - destination memory. Must be a pointer in memory.
bytCopy - n bytes to copy.
Want to use faster versions? Check these MemCpy here http://www.asmcommunity.net/board/index.php?topic=3350&highlight=MMX+MemCpy
:)
MemCpy PROC USES ebx esi edi srcMem:DWORD, dstMem:DWORD, bytCopy:DWORD
mov esi, srcMem
mov edi, dstMem
mov edx, bytCopy
xor ecx, ecx
@@CopyMem:
mov al, BYTE PTR [esi+ecx]
mov BYTE PTR [edi+ecx], al
inc ecx
cmp ecx, edx
jne @@CopyMem
ret
MemCpy ENDP
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 http://www.asmcommunity.net/board/index.php?topic=3350&highlight=MMX+MemCpy
:)
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 :).
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 :).
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)