文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>delphi内联汇编写的pos函数

delphi内联汇编写的pos函数

时间:2010-09-24  来源:江湖一键客

点击下载演示工程

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  function CharPos(src:char; str:pchar):Integer;
  
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i:Integer;
begin
    i:=CharPos('w', 'hello word');
    ShowMessage(IntToStr(i));
end;

function CharPos(src:char; str:pchar):Integer;
var
    n:Integer;
Label
    Find,NotFind;
begin
    n:=Length(str);
    {方向位清0,与之相反的是std(方向位置1),cld的作用是当每执行一次串操作指令后使得edi加1,std则减1}
    {下列的串操作指令是scasb,前缀repnz表示当当前edi指向的值不等于al中的值时重复执行此条指令}
    {如果使用std方向,则需要把edi指向串的末尾,即:str:=str+n+1; mov edi,str}
    {scasb:串扫描指令,用AL寄存器中的内容与由ES段DI指定的一个字节数据进行比较(减),
     若相等(结果为0)}
    asm
        cld;
        mov edi, str;
        mov al,src;
        mov ecx,n;
        repnz scasb;
        jz Find;
        mov result,-1;
        jmp NotFind;
Find:
        mov eax,n;
        sub eax,ecx;
        mov result,eax;
NotFind:
    end;
end;

end.

相关阅读 更多 +
排行榜 更多 +
马里奥赛车世界游戏手机版下载

马里奥赛车世界游戏手机版下载

赛车竞速 下载
无畏契约皮肤开箱器手游下载

无畏契约皮肤开箱器手游下载

休闲益智 下载
旭日之城官方正版下载

旭日之城官方正版下载

策略塔防 下载