diff --git a/src/string.asm b/src/string.asm index a91e1fc..d257102 100644 --- a/src/string.asm +++ b/src/string.asm @@ -60,30 +60,25 @@ strcpy: ; rsi* (arg) Pointer to src[] ; rdx (arg) Size of dest[] ; rcx* Counter for movsb -; r8* Backup for rdi +; r8* Backup for rdi (point to start of dest) ; r9* Backup for rsi -; r10* Current length of dest[] +; r10* Backup for rdi (point to end of dest) strcat: mov r8, rdi mov r9, rsi + call strlen + sub rdx, rax + dec rdi + mov r10, rdi mov rdi, rsi call strlen - mov rcx, rax - mov rdi, r8 - call strlen - mov r10, rax - mov rdi, r8 - add rcx, rax - cmp rcx, rdx - cmova rcx, rdx - cmp rcx, rdx + cmp rax, rdx jb .copy - dec rcx - .copy: - mov rdi, r8 + dec rdx + .copy: + mov rcx, rdx mov rsi, r9 - add rdi, r10 - sub rcx, r10 + mov rdi, r10 cld rep movsb mov byte [rdi], EOS