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

    xxx.asm

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrrev
    
    dllmain:
      mov eax,1
      ret 12
    
    ;------------------------------------------------;
    ;	反转字符串的字符。
    ;------------------------------------------------;
    astrrev:
      push ebp
      mov ebp,esp
    
      mov ecx,[p1]	; char *str
      mov edx,[p1]
      
      ;------------------------------------------------;
      ;	get last
      ;------------------------------------------------;
      .getLast:
      mov ah,[ecx]
      test ah,ah
      jz .getLastBreak
      inc ecx
      jmp .getLast
      
      .getLastBreak:
      dec ecx
      
      .rev:
      cmp ecx,edx
      jc .return	; 偶数ecx会小于edx
      je .return	; 奇数会相等
      
      ;------------------------------------------------;
      ;	交换字节
      ;------------------------------------------------;
      mov ah,[ecx]
      mov al,[edx]
      mov [edx],ah
      mov [ecx],al
      
      ; next
      dec ecx
      inc edx
      jmp .rev
      
      .return:
      mov eax,[p1]	; 返回原始指针
      mov esp,ebp
      pop ebp
      ret 4
    

    c++:

    #include <iostream>
    #include <Windows.h>
    #include <tchar.h>
    #include <string>
    
    typedef char* (CALLBACK* astrrev_t)(char* str);
    
    astrrev_t astrrev;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrrev = (astrrev_t)GetProcAddress(myDLL, "astrrev");
    
      char s[12] = "hello world";
      printf("%s, %s
    ", _strrev(s), s); // dlrow olleh, dlrow olleh
      printf("%s, %s
    ", astrrev(s), s); // hello world, hello world
      return 0;
    }
    
  • 相关阅读:
    uva 1374 快速幂计算
    uva 1343 非原创
    uva 11212
    uva 10603
    路径寻找问题……!
    bzoj 1008: [HNOI2008]越狱
    bzoj 1010: [HNOI2008]玩具装箱toy
    dp斜率优化小计
    bzoj 1002[FJOI2007]轮状病毒
    hihocoder #1114
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13743147.html
Copyright © 2011-2022 走看看