min[u](),max[u](),islower(),isupper(),print(),puts(),strlen(),strcpy(),strcat()
This commit is contained in:
67
string.asm
Normal file
67
string.asm
Normal 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
|
Reference in New Issue
Block a user