Delphi 允許在函數中直接用 asm 關鍵字替代 begin...end 塊,使純組合語言函數更加緊湊。
function Fun(x: Integer): Integer;
asm
mov eax, x {參數 x 自動進入 EAX}
inc eax {INC 指令:EAX 加 1}
end; {無需 begin/end,asm 直接結束函數}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
i := 8;
i := Fun(i);
ShowMessage(IntToStr(i)); {顯示 9}
end;
驗證點: 此例同時證明了 EAX 寄存器確實保存函數返回值,且 INC 指令與 Delphi Inc 函數語義一致。