Page 1 of 1

CopyMemory() only in ASM without API possible ?

Posted: Sat Sep 09, 2006 11:14 am
by newbie
Hello,

Just out of curiosity, I've looked at the /COMMENTED ASM output, and noticed the following :
; CopyMemory(*Fromaddr, *Toaddr, 5)
PUSH dword 5
PUSH dword [esp+PS28+4]
PUSH dword [esp+PS28+12]
CALL _PB_CopyMemory@12
Isn't it possible to copy directly the memory in pure ASM ?
MOV eax, Fromaddr
MOV Toaddr, eax

I'm sure it's not that simple, it would have already been implemented if it was ;) Just wondering if it's possible to do it only in ASM, and if yes (and how) is there any speed gain ?
I found on the forum a post about an optimised CopyMemory for AMD processors, but it was rather complex.

Nothing urgent, but if you know the answer... thanks you in advance ;)

Re: CopyMemory() only in ASM without API possible ?

Posted: Sun Sep 10, 2006 6:24 am
by Rescator
newbie wrote:Hello,

Just out of curiosity, I've looked at the /COMMENTED ASM output, and noticed the following :
; CopyMemory(*Fromaddr, *Toaddr, 5)
PUSH dword 5
PUSH dword [esp+PS28+4]
PUSH dword [esp+PS28+12]
CALL _PB_CopyMemory@12
Not sure how PB's code is, but I assume Fred made his own code for it.
newbie wrote:Isn't it possible to copy directly the memory in pure ASM ?
MOV eax, Fromaddr
MOV Toaddr, eax
That would just copy the pointers.
newbie wrote:I'm sure it's not that simple, it would have already been implemented if it was ;) Just wondering if it's possible to do it only in ASM, and if yes (and how) is there any speed gain ?
I found on the forum a post about an optimised CopyMemory for AMD processors, but it was rather complex.

Nothing urgent, but if you know the answer... thanks you in advance ;)
Your own asm copymem if it was to work on any x86 cpu would be limited to 4 bytes (32bit) and would be a asm loop somewhat similar to the above.
One can get a larger speedup using asm and mmx registers though.
I'm not sure if PB has a mmx optimized routine or not available. (cpu choice in compile options) though...