Adds strcat()
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
section .text
|
||||
global strlen
|
||||
global strcpy
|
||||
global strcat
|
||||
|
||||
;----- strlen(*str[]) -----;
|
||||
; Gets the length of given string
|
||||
@@ -24,7 +25,7 @@ strlen:
|
||||
;----- strcpy(*dest[], *src[], maxLength) -----;
|
||||
; Copies one string (src) into the other (dest), overwriting dest
|
||||
; NOTE: maxLength must never exceed size of dest[].
|
||||
; Return value: Pointer to dest
|
||||
; Return value: Pointer to dest[]
|
||||
; Used registers:
|
||||
; rax* (ret) Pointer to dest[]
|
||||
; rdi* (arg) Pointer to dest[]
|
||||
@@ -43,9 +44,48 @@ strcpy:
|
||||
cmp rcx, rdx
|
||||
jb .copy
|
||||
dec rcx
|
||||
.copy
|
||||
.copy:
|
||||
mov rdi, r8
|
||||
rep movsb
|
||||
mov byte [rdi], EOS
|
||||
mov rax, r8
|
||||
ret
|
||||
|
||||
;----- strcat(*dest[], *src[], maxLength) -----;
|
||||
; Concatenate src[] into dest[]
|
||||
; Return value: Pointer to dest[]
|
||||
; Used registers:
|
||||
; rax* (ret) Pointer to dest[]
|
||||
; rdi* (arg) Pointer to dest[]
|
||||
; rsi* (arg) Pointer to src[]
|
||||
; rdx (arg) Size of dest[]
|
||||
; rcx* Counter for movsb
|
||||
; r8* Backup for rdi
|
||||
; r9* Backup for rsi
|
||||
; r10* Current length of dest[]
|
||||
strcat:
|
||||
mov r8, rdi
|
||||
mov r9, rsi
|
||||
mov rdi, rsi
|
||||
call strlen ;16
|
||||
mov rcx, rax
|
||||
mov rdi, r8
|
||||
call strlen ;20
|
||||
mov r10, rax
|
||||
mov rdi, r8
|
||||
add rcx, rax ;36
|
||||
cmp rcx, rdx ;36 <> 32
|
||||
cmova rcx, rdx
|
||||
cmp rcx, rdx
|
||||
jb .copy
|
||||
dec rcx
|
||||
.copy:
|
||||
mov rdi, r8
|
||||
mov rsi, r9
|
||||
add rdi, r10
|
||||
sub rcx, r10
|
||||
cld
|
||||
rep movsb
|
||||
mov byte [rdi], EOS
|
||||
mov rax, r8
|
||||
ret
|
||||
|
Reference in New Issue
Block a user