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

    xxx.asm

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrcspn
    
    dllmain:
      mov eax,1
      ret 12
    
    ;---------------------------------------------------;
    ; 返回属于一组字符的字符在字符串中第一次出现的索引
    ;---------------------------------------------------;
    astrcspn:
      push ebp
      mov ebp,esp
      sub esp,8
      
      mov edx,[p1]	; char ptr 1
      mov ecx,[p2]	; char ptr 2
      xor eax,eax
      
      ; 保存str2指针,和ebx寄存器
      mov [ebp-4],ecx
      mov [ebp-8],ebx
      
      ;-------------------------------------;
      ; 遍历 str1
      ;-------------------------------------;
      .forStr1:
      mov bh,[edx]
      test bh,bh
      jz .return
      
      ;-------------------------------------;
      ; 遍历str2,如果相等退出函数
      ;-------------------------------------;
      .forStr2:
      mov bl,[ecx]
      test bl,bl
      jz .forbreak
      cmp bh,bl
      je .return
      inc ecx
      jmp .forStr2
      
      .forbreak:
      mov ecx,[ebp-4]
      inc edx
      inc eax
      jmp .forStr1
      
      ;-------------------------------------;
      ; 恢复ebx寄存器,恢复堆栈
      ;-------------------------------------;
      .return:
      mov ebx,[ebp-8]
      add esp,8
      mov esp,ebp
      pop ebp
      ret 8
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef size_t (CALLBACK* astrcspn_t)(const char* str1, const char* str2);
    
    astrcspn_t astrcspn;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrcspn = (astrcspn_t)GetProcAddress(myDLL, "astrcspn");
    
      const char* str1 = "fcba73";
      const char* str2 = "1234567890";
      printf("%d
    ", strcspn(str1,  str2)); // 4
      printf("%d
    ", astrcspn(str1, str2)); // 4
      return 0;
    }
    
  • 相关阅读:
    UOJ #455 [UER #8]雪灾与外卖 (贪心、模拟费用流)
    Codeforces 482E ELCA (LCT)
    Codeforces 798D Mike and distribution (构造)
    AtCoder AGC017C Snuke and Spells
    HDU 6089 Rikka with Terrorist (线段树)
    HDU 6136 Death Podracing (堆)
    AtCoder AGC032D Rotation Sort (DP)
    jenkins+python+kubectl实现批量更新k8s镜像
    Linux 下载最新kubectl版本的命令:
    jenkins X 和k8s CI/CD
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13734784.html
Copyright © 2011-2022 走看看