字符串查找汇编修改版,可供C++调用了
来源:互联网 发布:linux基础测试题 编辑:程序博客网 时间:2024/05/02 04:24
今天测试了一个PASCAL中的字符串搜索函数Pos,这个函数速度很快,由于需要所以修改了供C++使用,由于语言差异,内置的Pos函数参数都是ansistring类型,C++无法使用这种类型,所以修改了下,可以供C++使用了,函数如下:(参数为指针和整形,都是基本数据类型,就可以很好的供其他语言调用了)
function MyPos(const substr, str: PChar; SubstrLen,StrLen: Integer): Integer;
asm
push ebx
push esi
add esp, -16
test edx, edx
jz @NotFound
test eax, eax
jz @NotFound
mov esi, [ebp+8]
mov ebx, ecx
cmp esi, ebx
jl @NotFound
test ebx, ebx
jle @NotFound
dec ebx
add esi, edx
add edx, ebx
mov [esp+8], esi
add eax, ebx
mov [esp+4], edx
neg ebx
movzx ecx, byte ptr [eax]
mov [esp], ebx
jnz @FindString
sub esi, 2
mov [esp+12], esi
@FindChar2:
cmp cl, [edx]
jz @Matched0ch
cmp cl, [edx+1]
jz @Matched1ch
add edx, 2
cmp edx, [esp+12]
jb @FindChar4
cmp edx, [esp+8]
jb @FindChar2
@NotFound:
xor eax, eax
jmp @Exit0ch
@FindChar4:
cmp cl, [edx]
jz @Matched0ch
cmp cl, [edx+1]
jz @Matched1ch
cmp cl, [edx+2]
jz @Matched2ch
cmp cl, [edx+3]
jz @Matched3ch
add edx, 4
cmp edx, [esp+12]
jb @FindChar4
cmp edx, [esp+8]
jb @FindChar2
xor eax, eax
jmp @Exit0ch
@Matched2ch:
add edx, 2
@Matched0ch:
inc edx
mov eax, edx
sub eax, [esp+4]
@Exit0ch:
add esp, 16
pop esi
pop ebx
pop ebp
ret 4
@Matched3ch:
add edx, 2
@Matched1ch:
add edx, 2
xor eax, eax
cmp edx, [esp+8]
ja @Exit1ch
mov eax, edx
sub eax, [esp+4]
@Exit1ch:
add esp, 16
pop esi
pop ebx
pop ebp
ret 4
@FindString4:
cmp cl, [edx]
jz @Test0
cmp cl, [edx+1]
jz @Test1
cmp cl, [edx+2]
jz @Test2
cmp cl, [edx+3]
jz @Test3
add edx, 4
cmp edx, [esp+12]
jb @FindString4
cmp edx, [esp+8]
jb @FindString2
xor eax, eax
jmp @Exit1
@FindString:
sub esi, 2
mov [esp+12], esi
@FindString2:
cmp cl, [edx]
jz @Test0
@AfterTest0:
cmp cl, [edx+1]
jz @Test1
@AfterTest1:
add edx, 2
cmp edx, [esp+12]
jb @FindString4
cmp edx, [esp+8]
jb @FindString2
xor eax, eax
jmp @Exit1
@Test3:
add edx, 2
@Test1:
mov esi, [esp]
@Loop1:
movzx ebx, word ptr [esi+eax]
cmp bx, word ptr [esi+edx+1]
jnz @AfterTest1
add esi, 2
jl @Loop1
add edx, 2
xor eax, eax
cmp edx, [esp+8]
ja @Exit1
@RetCode1:
mov eax, edx
sub eax, [esp+4]
@Exit1:
add esp, 16
pop esi
pop ebx
pop ebp
ret 4
@Test2:
add edx,2
@Test0:
mov esi, [esp]
@Loop0:
movzx ebx, word ptr [esi+eax]
cmp bx, word ptr [esi+edx]
jnz @AfterTest0
add esi, 2
jl @Loop0
inc edx
@RetCode0:
mov eax, edx
sub eax, [esp+4]
add esp, 16
pop esi
pop ebx
end;
不过 ,需要特别注意,上面的函数数是Delphi的fastcall调用方式,如果需要给C++调用请在外层再导出一个stdcall调用的接口。
- 字符串查找汇编修改版,可供C++调用了
- NSMutableString 可修改字符串-Objective-C
- mon fping.monitor 已修改为可供monitor调用20121116在
- 汇编实验:查找匹配字符串
- 字符串,可调用方法
- C语言调用汇编
- C调用汇编函数
- 汇编调用C库函数
- C调用汇编
- C调用汇编
- C调用汇编
- 忙里偷闲-封装汇编编写的水波特效供C++调用
- c编写dll供c#调用
- C语言生成DLL供C#调用
- Framework层添加一个公共资源apk,可供应用调用
- 可供怀念的时光,都已经死掉了
- 可供怀念的时光,都已经死掉了
- 可供怀念的时光,都已经死掉了
- poj-1007 简单排序
- 兴趣的归兴趣,商业的归商业
- 第一次写的php代码
- 学一点C, 挣钱养家
- Android的蓝牙
- 字符串查找汇编修改版,可供C++调用了
- PCA的一些看法
- 专题3-2.宏定义与使用分析( 国嵌C语言视频)
- C++的总结图
- 二货小麦耍ios:网上找的一个判断是否为email的正则表达
- vs2005 设置 编译问题
- 页面显示System.Drawing.Image图片
- ios kvo
- 考研历程总结