memccpy.s 619 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. TEXT memccpy(SB),$0
  2. MOVL n+12(FP), CX
  3. CMPL CX, $0
  4. JEQ none
  5. MOVL p2+4(FP), DI
  6. MOVBLZX c+8(FP), AX
  7. CLD
  8. /*
  9. * find the character in the second string
  10. */
  11. REPN; SCASB
  12. JEQ found
  13. /*
  14. * if not found, set count to 'n'
  15. */
  16. none:
  17. MOVL $0, AX
  18. MOVL n+12(FP), BX
  19. JMP memcpy
  20. /*
  21. * if found, set count to bytes thru character
  22. */
  23. found:
  24. MOVL DI, AX
  25. SUBL p2+4(FP), AX
  26. MOVL AX, BX
  27. ADDL p1+0(FP), AX
  28. /*
  29. * copy the memory
  30. */
  31. memcpy:
  32. MOVL p1+0(FP), DI
  33. MOVL p2+4(FP), SI
  34. /*
  35. * copy whole longs
  36. */
  37. MOVL BX, CX
  38. SHRL $2, CX
  39. REP; MOVSL
  40. /*
  41. * copy the rest, by bytes
  42. */
  43. ANDL $3, BX
  44. MOVL BX, CX
  45. REP; MOVSB
  46. RET