Hi,
is there a way to copy a memory operand directly to another? Since in a mov instruction both operands cannot be memory operands, I have to write this.
mov dl,[edx+4]
mov [ecx+02h],dl
Is there a faster way to do this, saving cpu cycles. Maybe with MMX instructions? :thumbu
Best regards,
starshaper
Hi StarShaper,
Welcome to the forum.
If you are coding in a 32-bit environment, you could use the full 32-bit registers to copy data depending on your code. Have a look at Mark's assembly optimization tips :
http://www.mark.masmcode.com
the string "movs" instructions can do it, but require other registers to be set up, first
if they had a "mov Item1, Item2" instruction, it would probably be slower that the 2 instruction method
REP MOVSD is qute fast for dwords. There are many such algorithms here, be sure to use the search box near the top-left of the page.
\masm32\m32lib\memcopy.asm
Thanks @all! :thumbu
You should generally prefer working with al/ax for operations like that, these instructions are more optimized for size+speed.
Quote from: StarShaper on June 02, 2009, 05:45:20 PM
Is there a faster way to do this, saving cpu cycles. Maybe with MMX instructions? :thumbu
See e.g. Unsafe at any speed: Memcpy() banished in Redmond (http://www.masm32.com/board/index.php?topic=11432.0).
As Mark wrote, rep movsd is very fast, especially if source and destination are 16-byte aligned (which is not guaranteed for HeapAlloc'ed memory...).
MMX is not faster than rep movsd, and it trashes your FPU.
XMM does not trash the FPU, but movdqa requires 16-byte alignment (and is not significantly faster than rep movsd).
Finally, for everyday use with single dwords, there is the m2m macro:
m2m MyGlobVar1, MyGlobVar2
Your choices :bg