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

    xxx.asm:

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    %define p4 ebp+20
    
    section .text
      global dllmain
      export astrncat_s
    
    dllmain:
      mov eax,1
      ret 12
    
    ;------------------------------------------------;
    ;	将字符追加到字符串
    ;------------------------------------------------;
    astrncat_s:
      push ebp
      mov ebp,esp
      sub esp,8
      mov [ebp-4],ebx
    
      mov ecx,[p1]	; char *strDest
      mov eax,[p2]	; size_t numberOfElements
      mov edx,[p3]	; const char *strSource
      mov ebx,[p4]	; size_t count
     
      ; get strDest end
      .for1:
      test eax,eax
      jz .return
      cmp byte [ecx],0
      je .eachCopy
      inc ecx
      dec eax
      jmp .for1
      
      .eachCopy:
      test ebx,ebx
      jz .return
      test eax,eax
      jz .return
      mov [ebp-8],ebx
      
      ; copy
      mov bl,byte [edx]
      test bl,bl
      je .return
      mov byte [ecx],bl
      
      ; next
      mov ebx,[ebp-8]
      inc ecx
      inc edx
      dec eax
      dec ebx
      jmp .eachCopy
       
      .return:
      xor eax,eax
      mov ebx,[ebp+4]
      add esp,8
      mov esp,ebp
      pop ebp
      ret 16
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef int (CALLBACK* astrncat_s_t)(char* strDest, size_t numberOfElements, const char* strSource, size_t count); 
    
    astrncat_s_t astrncat_s;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrncat_s = (astrncat_s_t)GetProcAddress(myDLL, "astrncat_s");
      
      char s1[10] = "ab";
      const char* s2 = "cde";
      strncat_s(s1, sizeof(s1), s2, 2);
      printf("%s
    ", s1); // abcd
    
      //----------------------------------------------------------------------
    
      char s3[10] = "ab";
      const char* s4 = "cde";
      astrncat_s(s3, sizeof(s3), s4, 2);
      printf("%s
    ", s3); // abcd
      return 0;
    }
    
  • 相关阅读:
    Populating Next Right Pointers in Each Node II
    Populating Next Right Pointers in Each Node
    Construct Binary Tree from Preorder and Inorder Traversal
    Construct Binary Tree from Inorder and Postorder Traversal
    Path Sum
    Symmetric Tree
    Solve Tree Problems Recursively
    632. Smallest Range(priority_queue)
    609. Find Duplicate File in System
    poj3159最短路spfa+邻接表
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13742387.html
Copyright © 2011-2022 走看看