Files
klibc/string.asm

60 lines
812 B
NASM

section .text
global strlen
global strcpy
global strcat
;----- strlen(char* str) -----;
; return value: amount of characters before EOS was found
strlen:
push rbp
mov rbp, rsp
xor rax, rax
.findEOS:
cmp byte [rdi+rax], 0x0
je .quit
inc rax
jmp .findEOS
.quit:
leave
ret
;----- strcpy(char* dest, char* src) -----;
; return value: pointer to dest or NULL if nothing was copied
strcpy:
push rbp
mov rbp, rsp
xor rax, rax
xor rcx, rcx
.loop:
cmp byte [rsi], 0x0
je .0f
mov r10b, byte [rsi]
mov byte [rdi], r10b
inc rsi
inc rdi
inc rcx
jmp .loop
.0f:
cmp rcx, 0
jne .quit
xor rax, rax
.quit:
leave
ret
;----- strcat(char* dest, char* src) -----;
; return value: pointer to dest
strcat:
push rbp
mov rbp, rsp
call strlen
add rdi, rax
call strcpy
leave
ret