您的位置:首页 > 编程语言 > Delphi

Delphi Inline Assembler

2005-12-19 16:49 344 查看
program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
str: string;

{ Result := x + y }
function add1(x, y: Integer): Integer;
begin
asm
mov eax, x
add eax, y
mov @Result, eax
end;
end;

{ for I := 0 to Length(s) do s[i] := lower(s[i]) }
function test2(s: PChar): PChar;
begin
{ nest asm stmts inside a normal delphi proc then registers and flag are handled by delphi }
asm
mov ebx, s
xor esi, esi
@lab1:
cmp byte ptr [ebx + esi], 0
jz @lab2
or byte ptr [ebx + esi], $20
add esi, 1
jmp @lab1
@lab2:
mov @Result, ebx
end;
end;

begin
str := 'dO yOu kNoWn wHaT i MeAn?';

{ TODO -oUser -cConsole Main : Insert code here }
WriteLn(add1($FFFFFFFF, 2));
WriteLn(test2(PChar(str)));
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: