strcat.s 503 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. TEXT strcat(SB),$0
  2. MOVL $0, AX
  3. MOVQ $-1, CX
  4. CLD
  5. /*
  6. * find length of second string
  7. */
  8. MOVQ p2+8(FP), DI
  9. REPN; SCASB
  10. MOVQ DI, BX
  11. SUBQ p2+8(FP), BX
  12. /*
  13. * find end of first string
  14. */
  15. MOVQ RARG, DI
  16. REPN; SCASB
  17. /*
  18. * copy the memory
  19. */
  20. SUBQ $1, DI
  21. MOVQ p2+8(FP), SI
  22. /*
  23. * copy whole longs, if aligned
  24. */
  25. MOVQ DI, CX
  26. ORQ SI, CX
  27. ANDL $3, CX
  28. JNE c3
  29. MOVQ BX, CX
  30. SHRQ $2, CX
  31. REP; MOVSL
  32. /*
  33. * copy the rest, by bytes
  34. */
  35. ANDL $3, BX
  36. c3:
  37. MOVQ BX, CX
  38. REP; MOVSB
  39. MOVQ RARG, AX
  40. RET