strcat64.asm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. %include "defs.asm"
  2. ;************************* strcat64.asm ************************************
  3. ; Author: Agner Fog
  4. ; Date created: 2008-07-19
  5. ; Last modified: 2008-10-16
  6. ; Description:
  7. ; Faster version of the standard strcat function:
  8. ; char * strcat(char *dest, const char * src);
  9. ; Copies zero-terminated string from src to end of dest.
  10. ;
  11. ; Overriding standard function strcat:
  12. ; The alias ?OVR_strcat is changed to _strcat in the object file if
  13. ; it is desired to override the standard library function strcat.
  14. ;
  15. ; Optimization:
  16. ; Uses optimized functions A_strlen and A_memcpy.
  17. ;
  18. ; Copyright (c) 2009 GNU General Public License www.gnu.org/licenses
  19. ;******************************************************************************
  20. default rel
  21. global A_strcat: function ; Function A_strcat
  22. global EXP(strcat): function ; ?OVR removed if standard function strcat overridden
  23. ; Imported from strlen64.asm
  24. extern A_strlen
  25. ; Imported from memcpy64.asm
  26. extern A_memcpy
  27. SECTION .text align=16
  28. ; extern "C" char * A_strcat(char * dest, const char * src) {
  29. ; memcpy(dest+strlen(dest), src, strlen(src)+1);
  30. ; return dest
  31. ; }
  32. ; Function entry:
  33. A_strcat:
  34. EXP(strcat):
  35. %IFDEF WINDOWS
  36. %define Rpar1 rcx ; function parameter 1
  37. %define Rpar2 rdx ; function parameter 2
  38. %define Rpar3 r8 ; function parameter 3
  39. %ENDIF
  40. %IFDEF UNIX
  41. %define Rpar1 rdi ; function parameter 1
  42. %define Rpar2 rsi ; function parameter 2
  43. %define Rpar3 rdx ; function parameter 3
  44. %ENDIF
  45. push Rpar1 ; dest
  46. push Rpar2 ; src
  47. call A_strlen ; length of dest
  48. push rax ; strlen(dest)
  49. mov Rpar1, [rsp+8] ; src
  50. call A_strlen ; length of src
  51. pop Rpar1 ; strlen(dest)
  52. pop Rpar2 ; src
  53. add Rpar1, [rsp] ; dest + strlen(dest)
  54. lea Rpar3, [rax+1] ; strlen(src)+1
  55. call A_memcpy ; copy
  56. pop rax ; return dest
  57. ret
  58. ;A_strcat ENDP