memcpy() vs for()

Posts 16–19 of 19 · Page 2 of 2
Quote Originally Posted by mmbob View Post
memcpy is (at least with Visual Studio) an optimized assembly function. Hand written assembly will nearly always be faster than C++, unless the assembly coder has no idea what he is doing. I believe memcpy copies in DWORD chunks also, which would make it much faster than a for loop.
Nigga knows shit.
Then may I suggest inline assembly using the "mov" assembly statement
Quote Originally Posted by Departure View Post
Then may I suggest inline assembly using the "mov" assembly statement
you can only copy/write 1, 2 or 4 bytes with mov.

Code:
mov byte ptr [address], al
mov word ptr [address], ax
mov dword ptr [address], eax
Yes true Gordon, if you do a straight mov... Look at example below to explain what I mean using REP MOVSB

Code:
procedure CopyMemory(Destination, Source:Pointer; dwSize:LongWord);
asm
  PUSH ECX
  PUSH ESI
  PUSH EDI
  MOV EDI, Destination
  MOV ESI, Source
  MOV ECX, dwSize
  REP MOVSB
  POP EDI
  POP ESI
  POP ECX
end;

All we do here is use MOVSB which will mov bytes from address in ESI to address in EDI, this will repeat using the REP statement Untill ECX = 0 allowing us to use any amount of bytes.

Reference
http://faydoc.tripod.com/cpu/movsb.htm
Posts 16–19 of 19 · Page 2 of 2

Post a Reply

Tags for this Thread

None

Talk with us