Since we've got the converting C to Pas thread, I thought some of you are familiar with inline ASM. The reason is that it is obviously 32 bit Assembler. (It is originally written for Delphi but compiles with FPC, too). I want to port the program to 64 bit, so porting to Pascal would be an advantage. Speed issues are no problem. Of course it is also possible to convert the ASM part to 64 bit assembler ... Now here's the piece of code:
Code:
asm       push esi               // esi, edi, ebp and ebx must be kept
       push edi               // (we use only esi and edi here).
       sub esp, StkUsage      // make room on stack
       mov edi, esp           // set destination of mem copy, it is the stack
       mov esi, StkAdr        // set source of mem copy, it is Addr(ExtStk)
       mov ecx, StkUsage      // prepare ecx to copy StkUsage bytes
       shr ecx, 2             // divide by 4 to perform DWORD-copy (is faster)


       //add edi, StkUsage;
       //sub edi,4
       //add esi, StkUsage;
       //sub esi,4
       cld                    // choose copy direction
       rep movsd              // do DWORD-copy


       cmp RegCall, true
       jnz @@EXEC
       mov EAX, _EAX
       mov EDX, _EDX
       mov ECX, _ECX


       @@EXEC:
       call Adr               // execute the external function
                              // esp is restored by the external function
                              // (except for cdecl-convention)
       pop edi                // restore edi...
       pop esi                // ...and esi
       mov _EAX,eax
     end;                     // asm