nasm astrlwr_s函数 x86
xxx.asm
%define p1 ebp+8
%define p2 ebp+12
%define p3 ebp+16
section .text
global dllmain
export astrlwr_s
dllmain:
mov eax,1
ret 12
;-----------------------------------------;
; 将字符串转换为小写
;-----------------------------------------;
astrlwr_s:
push ebp
mov ebp,esp
mov eax,[p1] ; str ptr
mov ecx,[p2] ; numberOfElements
.for:
test ecx,ecx
jz .return
mov dl,[eax]
test dl,dl
jz .return
;----------------------------------------;
; 如果 < 0x41 next
;----------------------------------------;
cmp dl,41h
jb .next
;----------------------------------------;
; 如果 > 0x5A next
;----------------------------------------;
cmp dl,5Ah
ja .next
add dl,20h
mov [eax],dl
.next:
dec ecx
inc eax
jmp .for
.return:
xor eax,eax
mov esp,ebp
pop ebp
ret 8
c++:
#include <iostream>
#include <Windows.h>
typedef int (CALLBACK* astrlwr_s_t)(char* str, size_t numberOfElements);
astrlwr_s_t astrlwr_s;
int main()
{
HMODULE myDLL = LoadLibraryA("xxx.dll");
astrlwr_s = (astrlwr_s_t)GetProcAddress(myDLL, "astrlwr_s");
char a[10] = "aBcD";
printf("%d, %s\n", _strlwr_s(a, 10), a); // abcd
char b[10] = "aBcD";
printf("%d, %s\n", astrlwr_s(b, 10), b); // abcd
return 0;
}