strcat: Better logic for determining max amount of characters to copy
This commit is contained in:
@@ -60,30 +60,25 @@ strcpy:
|
|||||||
; rsi* (arg) Pointer to src[]
|
; rsi* (arg) Pointer to src[]
|
||||||
; rdx (arg) Size of dest[]
|
; rdx (arg) Size of dest[]
|
||||||
; rcx* Counter for movsb
|
; rcx* Counter for movsb
|
||||||
; r8* Backup for rdi
|
; r8* Backup for rdi (point to start of dest)
|
||||||
; r9* Backup for rsi
|
; r9* Backup for rsi
|
||||||
; r10* Current length of dest[]
|
; r10* Backup for rdi (point to end of dest)
|
||||||
strcat:
|
strcat:
|
||||||
mov r8, rdi
|
mov r8, rdi
|
||||||
mov r9, rsi
|
mov r9, rsi
|
||||||
|
call strlen
|
||||||
|
sub rdx, rax
|
||||||
|
dec rdi
|
||||||
|
mov r10, rdi
|
||||||
mov rdi, rsi
|
mov rdi, rsi
|
||||||
call strlen
|
call strlen
|
||||||
mov rcx, rax
|
cmp rax, rdx
|
||||||
mov rdi, r8
|
|
||||||
call strlen
|
|
||||||
mov r10, rax
|
|
||||||
mov rdi, r8
|
|
||||||
add rcx, rax
|
|
||||||
cmp rcx, rdx
|
|
||||||
cmova rcx, rdx
|
|
||||||
cmp rcx, rdx
|
|
||||||
jb .copy
|
jb .copy
|
||||||
dec rcx
|
dec rdx
|
||||||
.copy:
|
.copy:
|
||||||
mov rdi, r8
|
mov rcx, rdx
|
||||||
mov rsi, r9
|
mov rsi, r9
|
||||||
add rdi, r10
|
mov rdi, r10
|
||||||
sub rcx, r10
|
|
||||||
cld
|
cld
|
||||||
rep movsb
|
rep movsb
|
||||||
mov byte [rdi], EOS
|
mov byte [rdi], EOS
|
||||||
|
Reference in New Issue
Block a user