65 lines
917 B
NASM
65 lines
917 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 (note that EOS is always copied to dest)
|
|
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:
|
|
mov byte [rdi], 0x0
|
|
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
|
|
|
|
push rdi
|
|
sub rsp, 8
|
|
call strlen
|
|
add rdi, rax
|
|
call strcpy
|
|
add rsp, 8
|
|
pop rax
|
|
|
|
leave
|
|
ret
|