我需要處理來自舊式Mac時代(舊式Motorola CPU)的文件。字節是大端,所以我有一個功能,交換和INT64英特爾小端。該功能是ASM,適用於32位CPU,但不適用於64位。對於64位,我有一個不是ASM的功能。我想結合使用IFDEF的功能。我可以這樣做嗎?這會成爲一個問題嗎?將ASM與非asm編碼(或需要SwapInt64 ASM功能)相結合
interface
function SwapInt64(Value: Int64): Int64; assembler;
implementation
{$IFDEF CPUx86}
function SwapInt64(Value: Int64): Int64; assembler; { Does not work on 64 bit } {
asm
MOV EDX,[DWORD PTR EBP + 12]
MOV EAX,[DWORD PTR EBP + 8]
BSWAP EAX
XCHG EAX,EDX
BSWAP EAX
end;
{$else}
function SwapInt64 (Value: Int64): Int64;
var P: PInteger;
begin
Result: = (Value shl 32) or (Value shr 32);
P: = @Result;
P ^: = (Swap (P ^) shl 16) or (Swap (P^shr 16));
Inc (P);
P ^: = (Swap (P ^) shl 16) or (Swap (P^shr 16));
end;
{$ENDIF}
我覺得編譯器會正確編譯/調用相應的功能不管一個是ASM,另一個是帕斯卡。
Mac也使用小端。你實際上是在尋找網絡來主辦功能?你爲什麼覺得需要重新實現它們?你爲什麼想要使用asm?那不是你造成什麼問題嗎?如果你使用Pascal,你會回家並且乾燥? –
@ DavidHeffernan-對不起。我的意思是'老蘋果'。大端(sparc)。 – Ampere
@DavidHeffernan - 請參閱與數據來源有關的說明(舊mac) – Ampere