nasm astrspn函数 x86
xxx.asm
%define p1 ebp+8
%define p2 ebp+12
%define p3 ebp+16
section .text
global dllmain
export astrspn
dllmain:
mov eax,1
ret 12
;---------------------------------------------------;
; 返回不属于一组字符的字符串中第一个字符的索引
;---------------------------------------------------;
astrspn:
push ebp
mov ebp,esp
sub esp,8
mov edx,[p1] ; const char *str
mov ecx,[p2] ; const char *strCharSet
xor eax,eax
; 临时变量
mov [ebp-4],ecx
mov [ebp-8],ebx
;-------------------------------------;
; 遍历 str
;-------------------------------------;
.forStr:
mov bh,[edx]
test bh,bh
jz .return
;-------------------------------------;
; 遍历 strCharSet
;-------------------------------------;
.forStrCharSet:
mov bl,[ecx]
test bl,bl
jz .return ; 没找到退出函数
cmp bh,bl
je .forbreak ; 相等 next str
inc ecx
jmp .forStrCharSet ; 不相等 next strCharSet
.forbreak:
mov ecx,[ebp-4]
inc edx
inc eax
jmp .forStr
.return:
mov ebx,[ebp-8]
add esp,8
mov esp,ebp
pop ebp
ret 8
c++:
#include <iostream>
#include <Windows.h>
typedef int (CALLBACK* astrspn_t)(const char* str, const char* strCharSet);
astrspn_t astrspn;
int main()
{
HMODULE myDLL = LoadLibraryA("xxx.dll");
astrspn = (astrspn_t)GetProcAddress(myDLL, "astrspn");
printf("%d\n", strspn( "abbbc", "ab")); // 4
printf("%d\n", astrspn("abbbc", "ab")); // 4
return 0;
}