Reputation: 1
I am converting a Delphi 6 project on Windows XP to Delphi 11 on Windows 11. I have an issue that is most likely common, but not knowing Assembly I am a bit confused.
//This complies fine in 64 or 32 bit
{$IFDEF WIN32}
asm
mov edx, aStream
mov eax, aObject
call aPointer
end;
{$ENDIF}
//this does not compile in 64 due to inline Assembly
{$IFDEF WIN64}
asm
mov ecx, aStream
mov eax, aObject
call aPointer
end;
{$ENDIF}
Is there a good reference I can use to learn this quickly? Is there a simple solution?
Upvotes: 0
Views: 518
Reputation: 43033
So the best asm
is the no-asm
to write.
We can replace
{$IFDEF WIN32}
asm
mov edx, aStream
mov eax, aObject
call aPointer
end;
{$ENDIF}
with native pascal code.
This is a no-operation, just a function call.
Just replace it with
type
TMethodCallWithStream = procedure(Instance: TObject; Str: TStream);
...
TMethodCallWithStream(aPointer)(aObject, aStream);
It won't be slower than previous asm code, and it will work on all platforms, both Win32 and WIN64.
Here self
is passed as first argument. So the actual method called is something like MethodName(Stream: TStream);
But this is how methods are called: self
is passed as first argument - eax
in Win32 assembly. Then the 2nd argument is in fact the first method argument in the source - edx
in Win32 assembly.
You could use a TMethod
wrapper, but it would be more complicated.
See the Delphi documentation about reference about how methods are called:
Under the register convention, Self behaves as if it were declared before all other parameters. It is therefore always passed in the EAX register.
Edit/Hint: When you do some refactoring for a new target, the less rewrite, the better. You should use the working target (here Win32) as reference, and always validate any modification you made in the code on it. So here, replacing asm with pascal code does make sense. Don't rewrite any further yet. Then when everything compiles on both Win32 and Win64, ensure it still runs on Win32, then see if it is fine on Win64. Use the debugger to validate each modification. My advice with refactoring is to first make it run, never break the existing, and then make it better - if you have time.
Upvotes: 6