min[u](),max[u](),islower(),isupper(),print(),puts(),strlen(),strcpy(),strcat()

This commit is contained in:
2025-06-23 15:07:55 +02:00
parent 4820e6242f
commit 2f5e3202db
4 changed files with 407 additions and 0 deletions

67
string.asm Normal file
View File

@ -0,0 +1,67 @@
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
push rdi
sub rsp, 8
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:
pop rax
add rsp, 8
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 rdi
leave
ret