Please note that you're throwing everything together here.
First of the
safecall calling convention is only intended for functions that normally return a
HRESULT on the non-Pascal side (mainly in the context of Windows COM (as in Component Object Model) programming). So this calling convention is
not what you want.
Second the
Mode has nothing to do with the calling convention or the prologues of routines. This is only influenced by the calling convention and the
nostackframe modifier.
Third if you have an assembly block inside a function you need to specify which registers are modified so that the compiler's register allocator can spill them correctly (this is more efficient than saving/restoring all registers; depending on the architecture there can be many registers (e.g. x86_64 or PPC), also this allows the use of unknown assembly opcodes by manually encoding them). The syntax for this is as follows:
begin
// some Pascal code
asm
// let's assume the following:
mov ebx, ecx
mov ecx, eax
mov eax, ebx
end ['ebx', 'ecx', 'eax']; // these registers where modified
// some more Pascal code
end;
This is not necessary for pure assembly functions (those consisting only of a
asm … end block).
Fourth you're quoting the Turbo Pascal calling convention. However 32-bit or 64-bit code
is not using the Turbo Pascal calling convention. In fact that calling convention is provided by FPC only on the 16-bit i8086 target. On other platforms you need to adhere to the corresponding ABIs. On nearly all platforms FPC follows the default ABI of the C compiler (aka
cdecl). The only exceptions are i386 where there are also the
register (default),
stdcall and
pascal calling conventions, x86_64-win64 with the
vectorcall calling convention and m68k with the
register (default) calling convention.
When you work with assembly and functions you
must learn at least about those calling conventions that you are using for those platforms that you are supporting with assembly.
See also:
X86 calling conventions on Wikipedia