; M13_COPYSTR.ASM

.586P
.MODEL FLAT, stdcall ; Flat memory model
PUBLIC COPYSTR

_TEXT SEGMENT
; Procedure for copying the null-terminated source string to the target string.
;
; Input:
;   str_dest...Target string [ EBP + 08H ]
;   str_src....Source string [ EBP + 0CH ]
; Output:
;   EAX........address of the target string
;
; WARNING! target string length is unchecked
;
COPYSTR PROC  str_dest: DWORD, str_src: DWORD
        MOV   ESI, str_src  ; DWORD PTR [ EBP + 0CH ]
        MOV   EDI, str_dest ; DWORD PTR [ EBP + 08H ]
L1:
        MOV   AL, BYTE PTR [ESI]
        MOV   BYTE PTR [EDI], AL
        CMP   AL, 0
        JE    L2
        INC   ESI
        INC   EDI
        JMP   L1
L2:
        MOV   EAX, DWORD PTR [ EBP + 08H ]
        RET
COPYSTR ENDP

_TEXT ENDS

END

