flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Vortex 09 Nov 2004, 17:20
Hutch's masm32.lib provides a function for this purpose, it should not be so hard to translate it to Fasm:
Code: align 4 MemCopy proc public uses esi edi Source:PTR BYTE,Dest:PTR BYTE,ln:DWORD ; --------------------------------------------------------- ; Copy ln bytes of memory from Source buffer to Dest buffer ; ~~ ~~~~~~ ~~~~ ; USAGE: ; invoke MemCopy,ADDR Source,ADDR Dest,4096 ; ; NOTE: Dest buffer must be at least as large as the source ; buffer otherwise a page fault will be generated. ; --------------------------------------------------------- cld mov esi, [Source] mov edi, [Dest] mov ecx, [ln] shr ecx, 2 rep movsd mov ecx, [ln] and ecx, 3 rep movsb ret MemCopy endp _________________ Code it... That's all... |
|||
![]() |
|
Tomasz Grysztar 09 Nov 2004, 18:00
It would also be good to ensure the proper alignment (some MOVSB's both on the beginning and at the end might be needed). Though it might not be possible to make the source and destination address be both aligned on dword for MOVSD, for example.
|
|||
![]() |
|
Matrix 09 Nov 2004, 18:20
what do you think on my memcopy macro? :DDD
It always chooses the shortest form to copy ![]() well i put it in main because its not really a macro, its more a procedure/algorithm http://board.flatassembler.net/topic.php?p=17998#17998 |
|||
![]() |
|
Reverend 10 Nov 2004, 13:26
I guess you didn't look precisely at my macro. Look at your code Vortex:
Vortex wrote:
If my macro is given a constant value it checks this constant number for being a multiple of 4. If so the last 3 lines of your code are useless (data can be copied using only movsd) and my macro doesn't put them in code. If the value given is not a multiple of 4 or it is given as a register or variable then it does the same as the code you've pasted. But for special circumstances it is smaller. Matrix: I can't move it to main, because, a procedure gets parameters from stack and my macro makes some operations on the number of bytes to copy if it's a constant value. Such operations are impossible if given on a stack. Privalov: It does align it. Look: it counts how many dwords are there and moves them with movsd, and then it counts how many bytes are left to align it by counting size mod 4 and movsb it. |
|||
![]() |
|
Tomasz Grysztar 10 Nov 2004, 16:49
But the address of each double word may not be aligned on 4 boundary. For example when you start moving from address 10001h, it might be good to use one MOVSB first, then as much of (aligned) MOVSD instructions as fit, and then fill the rest with MOVSB instructions again.
|
|||
![]() |
|
Matrix 10 Nov 2004, 17:36
Reverend wrote: I guess you didn't look precisely at my macro. Look at your code Vortex: sorry i was not thinking of moving your thread, i just put my code there and linked it here, maeby it helps ![]() (my code was not a macro so i post it there) |
|||
![]() |
|
Reverend 11 Nov 2004, 10:06
Privalov wrote: But the address of each double word may not be aligned on 4 boundary. For example when you start moving from address 10001h, it might be good to use one MOVSB first, then as much of (aligned) MOVSD instructions as fit, and then fill the rest with MOVSB instructions again. Ok, now I know what you meant. It's a nice idea, but addresses are in 99% not a constant value so no preprocessing can be done. Of course it might be done during runtime using another instructions, but to tell you the truth I didn't wrote these to be extra-fast, just a small example to put it somewhere in the code |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.