strcpy 模拟

; Prototype:
;
void strcpy(char *destination, char *source)
;
Param: push from left to right
;
destination: address where to save string.
;
source : address where to string are.
;
Function own the stack and response for pop stack.
strcpy PROC NEAR32
push ebp
mov ebp, esp
push esi
push edi
pushf

mov esi, [ebp + 8] ; Get source address.
mov edi, [ebp + 12] ; Get destination address.
whileNoNull:
cmp BYTE PTR [esi], 0 ; If null, terminated.
je endWhileNoNull
movsb ; Copy characters from source to destination.
jmp whileNoNull ; Copy one by one.
endWhileNoNull:
mov BYTE PTR [edi], 0 ; Appending a null character to the end of destination string.

popf
pop edi
pop esi
pop ebp
ret 8 ; Two parameter take up eight byte on stack
strcopy ENDP

  

posted @ 2011-08-27 13:19  walfud  阅读(273)  评论(0编辑  收藏  举报