Trond wrote:All registers except eax, ecx and edx must always be preserved, else you may end up with wrong expression results in the caller.
Ok, seems i must update some of my procedures. ^^
Can some one tell me why the first parameter on x64 is on rsp+48?
On x86 it is on esp+4 which makes sense. 4 bytes for the return address.
For what are the 40 bytes of stack used on x64?
Updated SwapMemoryASM3 x86 and x64.
Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Procedure MemorySwapASM3(*src, *dst, len.i)
!push esi
!push edi
!mov esi,[esp+12]
!mov edi,[esp+16]
!mov ecx,[esp+20]
!push ecx
!shr ecx,2
!align 4
!MemorySwapASM3_LoopStart1:
!cmp ecx,0
!je MemorySwapASM3_LoopEnd1
!mov eax,[esi]
!mov edx,[edi]
!mov [esi],edx
!mov [edi],eax
!add esi,4
!add edi,4
!dec ecx
!jmp MemorySwapASM3_LoopStart1
!MemorySwapASM3_LoopEnd1:
!pop ecx
!and ecx,3
!MemorySwapASM3_LoopStart2:
!cmp ecx,0
!je MemorySwapASM3_LoopEnd2
!mov al,[esi]
!mov dl,[edi]
!mov [esi],dl
!mov [edi],al
!inc esi
!inc edi
!dec ecx
!jmp MemorySwapASM3_LoopStart2
!MemorySwapASM3_LoopEnd2:
!pop edi
!pop esi
ProcedureReturn #True
EndProcedure
CompilerElse
Procedure MemorySwapASM3(*src, *dst, len.i)
!push rsi
!push rdi
!mov rsi,[rsp+64]
!mov rdi,[rsp+72]
!mov rcx,[rsp+80]
!push rcx
!shr rcx,3
!align 4
!MemorySwapASM3_LoopStart1:
!cmp rcx,0
!je MemorySwapASM3_LoopEnd1
!mov rax,[rsi]
!mov rdx,[rdi]
!mov [rsi],rdx
!mov [rdi],rax
!add rsi,8
!add rdi,8
!dec rcx
!jmp MemorySwapASM3_LoopStart1
!MemorySwapASM3_LoopEnd1:
!pop rcx
!and rcx,7
!MemorySwapASM3_LoopStart2:
!cmp rcx,0
!je MemorySwapASM3_LoopEnd2
!mov al,[rsi]
!mov dl,[rdi]
!mov [rsi],dl
!mov [rdi],al
!inc rsi
!inc rdi
!dec rcx
!jmp MemorySwapASM3_LoopStart2
!MemorySwapASM3_LoopEnd2:
!pop rdi
!pop rsi
ProcedureReturn #True
EndProcedure
CompilerEndIf