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

    xxx.asm:

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrchr
    
    dllmain:
      mov eax,1
      ret 12
    
    astrchr:
      push ebp
      mov ebp,esp
      
      mov eax,[p1]	; char ptr
      mov ecx,[p2]	; char
      
      .for:
      ;-------------------------------------------;
      ;   找到后返回第一次出现的指针
      ;-------------------------------------------;
      cmp [eax],cl
      je .return
      inc eax
      
      ;-------------------------------------------;
      ;   如果找不到该字符,则该函数返回空指针
      ;-------------------------------------------;
      cmp byte [eax],0
      je .error
      jmp .for
      
      .error:
      xor eax,eax
    
      .return:
      mov esp,ebp
      pop ebp
      ret 8
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef char*(CALLBACK* astrchr_t)(const char* str, int character);
    
    astrchr_t astrchr;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrchr = (astrchr_t)GetProcAddress(myDLL, "astrchr");
    
      char str[] = "hello world";
    
      char* pch = strchr(str, 'l');
      printf("%s
    ", pch); // llo world
    
      char* pch2 = astrchr(str, 'l');
      printf("%s
    ", pch2); // llo world
    
      //==============================//
    
      char* pch3 = strchr(str, 'b');
      printf("%s
    ", pch3); // (null)
    
      char* pch4 = astrchr(str, 'b');
      printf("%s
    ", pch4); // (null)
      return 0;
    }
    
  • 相关阅读:
    历史版本xcode的下载
    mac上安装hg
    xcode不能抓帧
    window buffer alignment
    highp 和 mediump
    AFBC mali
    AO composition
    gpu memory wait
    L2 cache//bifrost --- cortex-A55
    效果样式
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13723536.html
Copyright © 2011-2022 走看看