zoukankan      html  css  js  c++  java
  • nasm astrcmp函数 x86

    xxx.asm:

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrcmp
    
    dllmain:
      mov eax,1
      ret 12
    
    astrcmp:
      push ebp
      mov ebp,esp
      push ebx
      
      mov eax,[p1]	; char ptr 1
      mov ecx,[p2]	; char ptr 2
      
      .for:
      mov dl,[eax]
      mov bl,[ecx]
      cmp dl,bl
      jc .r1
      jne .r3
      test dl,bl
      jz .r2
      inc eax
      inc ecx
      jmp .for
      
      ;-----------------------------------------------------;
      ; <0 第一个不匹配的字符在ptr1中的值比在ptr2中的值低
      ;-----------------------------------------------------;
      .r1:
      xor eax,eax
      not eax
      jmp .return
      
      ;-----------------------------------------------------;
      ; 0 两个字符串的内容相等
      ;-----------------------------------------------------;
      .r2:
      xor eax,eax
      jmp .return
      
      ;-----------------------------------------------------;
      ; >0 第一个不匹配的字符在ptr1中的值大于在ptr2中的值
      ;-----------------------------------------------------;
      .r3:
      mov eax,1
      jmp .return
      
      .return:
      pop ebx
      mov esp,ebp
      pop ebp
      ret 8
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef int(CALLBACK* astrcmp_t)(const char* str1, const char* str2);
    
    astrcmp_t astrcmp;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrcmp = (astrcmp_t)GetProcAddress(myDLL, "astrcmp");
    
      printf("%x
    ",  astrcmp("12", "22")); // -1
      printf("%x
    ",  astrcmp("12", "12")); // 0
      printf("%x
    ",  astrcmp("22", "12")); // 1
      return 0;
    }
    
  • 相关阅读:
    开始使用 UIAlertController 吧
    SegmentControl 那些令人烦恼的事儿
    UIWindow 实现遮盖导航条的蒙版
    C++语言-09-多任务
    C++语言-08-命名空间
    使用 UICollectionView 实现日历签到功能
    C++语言-07-异常处理和信号处理
    Django模板(三)
    数据可视化包
    数据分析核心包
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13723604.html
Copyright © 2011-2022 走看看