diff --git a/src/string.asm b/src/string.asm index 011f110..0987865 100644 --- a/src/string.asm +++ b/src/string.asm @@ -27,26 +27,23 @@ strlen: ; Return value: Pointer to dest ; Used registers: ; rax* (ret) Pointer to dest[] -; rdi (arg) Pointer to dest[] -; rsi (arg) Pointer to src[] -; rdx (arg) Max amount of characters to copy / size of dest[] Must never be greater than size of dest[]! +; rdi* (arg) Pointer to dest[] +; rsi* (arg) Pointer to src[] +; rdx (arg) Size of dest[] ; rcx* Counter for movsb ; r8* Backup for rdi strcpy: mov r8, rdi mov rdi, rsi call strlen - mov rcx, rdx - cmp rcx, rax - je .decMaxLen ;rcx-1 for EOS - ja .setMaxLen ;set rcx to strlen(src) - jmp .copy - .decMaxLen: + inc rax + cmp rax, rdx + cmova rcx, rdx + cmovbe rcx, rax + cmp rcx, rdx + jb .copy dec rcx - jmp .copy - .setMaxLen: - mov rcx, rax - .copy: + .copy mov rdi, r8 rep movsb mov byte [rdi], EOS