• 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
    ", strspn( "abbbc", "ab")); // 4
      printf("%d
    ", astrspn("abbbc", "ab")); // 4
      return 0;
    }
    
  • 相关阅读:
    思考题13-1.b
    算法导论 第三版 9.3-8
    算法导论第三版思考题8-4
    算法导论第三版思考题8-3.b
    算法导论第三版思考题8-3.a
    算法导论第三版思考题8-2.e
    算法导论 第三版 思考题 7-4
    test
    一个朋友面试时遇到的算法题(怎么组合后得到最大整数)
    监听器模式、观察者模式
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13743312.html
Copyright © 2020-2023  润新知