内联汇编程序在德尔福中的工作方式与在GCC中的工作方式不同。对于初学者来说,你没有同类型的德尔福宏观和模板支撑,所以如果你想使用一个声明,一旦通用汇编程序,你必须将其声明为一个函数:
function ShiftArithmeticRight(aShift: Byte; aValue: LongInt): LongInt;
{$IFDEF WIN64}
asm
sar edx,cl
mov eax,edx
end;
{$ELSE}
{$IFDEF CPU386}
asm
mov cl,al
sar edx,cl
mov eax,edx
end;
{$ELSE}
begin
if aValue < 0 then
Result := not (not aValue shr aShift)
else
Result := aValue shr aShift;
end;
{$ENDIF}
{$ENDIF}
在Delphi中,内联汇编程序必须在使用它的地方实现,并且只支持32位。在这样的模块中,您可以自由使用EAX,ECX,EDX以及周围代码中的任何标识符。例如:
var
lValue: LongInt;
lShift: Byte;
begin
// Enter pascal code here
asm
mov cl,lShift
sar lValue,cl
end;
// Enter pascal code here
end;
我的建议是将此代码转换为Pascal而不是汇编程序。 – 2012-02-24 12:07:35