nasm astricmp函数 x86
xxx.asm:
%define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export astricmp dllmain: mov eax,1 ret 12 ;-------------------------------------------; ; 对字符串(char)进行不区分大小写的比较。 ;-------------------------------------------; astricmp: push ebp mov ebp,esp sub esp,12 %define pStr1 edx %define pStr2 ecx mov pStr1,[p1] ; char ptr1 mov pStr2,[p2] ; char ptr2 mov [ebp-12],ebx .for: mov [ebp-4],pStr1 mov [ebp-8],pStr2 mov bh,[pStr1] mov bl,[pStr2] mov al,bh push eax call _toLowerCase mov bh,al mov al,bl push eax call _toLowerCase mov bl,al test bh,bl jz .identical cmp bh,bl jc .less jne .greater ; 不相等跳 mov pStr1,[ebp-4] mov pStr2,[ebp-8] inc pStr1 inc pStr2 jmp .for ;-----------------------------------------------------; ; <0 string1 less than string2 ;-----------------------------------------------------; .less: xor eax,eax not eax jmp .return ;-----------------------------------------------------; ; 0 string1 identical to string2 ;-----------------------------------------------------; .identical: xor eax,eax jmp .return ;-----------------------------------------------------; ; >0 string1 greater than string2 ;-----------------------------------------------------; .greater: mov eax,1 jmp .return .return: mov ebx,[ebp-12] add esp,12 mov esp,ebp pop ebp ret 8 _toLowerCase: push ebp mov ebp,esp mov al,[p1] ; char ;----------------------------------------; ; 如果 < 0x41 return ;----------------------------------------; cmp al,41h jb .return ;----------------------------------------; ; 如果 > 0x5A return ;----------------------------------------; cmp al,5Ah ja .return add al,20h .return: mov esp,ebp pop ebp ret 4
c++:
#include <iostream> #include <Windows.h> typedef size_t (CALLBACK* astricmp_t)(const char* str1, const char* str2); astricmp_t astricmp; int main() { HMODULE myDLL = LoadLibraryA("xxx.dll"); astricmp = (astricmp_t)GetProcAddress(myDLL, "astricmp"); printf("%d\n", _stricmp("a", "a")); // 0 printf("%d\n", _stricmp("a", "A")); // 0 printf("%d\n", _stricmp("", "")); // 0 printf("%d\n", _stricmp("a", "b")); // -1 printf("%d\n", _stricmp("b", "a")); // 1 printf("//----------------------------------------\n"); printf("%d\n", astricmp("aaaa", "AaA")); // 0 printf("%d\n", astricmp("a", "A")); // 0 printf("%d\n", astricmp("", "")); // 0 printf("%d\n", astricmp("a", "b")); // -1 printf("%d\n", astricmp("b", "aaaaa")); // 1 return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· 赶AI大潮:在VSCode中使用DeepSeek及近百种模型的极简方法
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地