Get rid of unneeded function prologues/epilogues
This commit is contained in:
43
string.asm
43
string.asm
@ -10,9 +10,6 @@ section .text
|
||||
;----- 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
|
||||
@ -21,14 +18,10 @@ strlen:
|
||||
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
|
||||
|
||||
mov r11, rdi
|
||||
xor rax, rax
|
||||
xor rcx, rcx
|
||||
@ -49,14 +42,10 @@ strcpy:
|
||||
mov rax, rdi
|
||||
|
||||
.quit:
|
||||
leave
|
||||
ret
|
||||
;----- strlcpy(char* dest, char* src, int size) -----;
|
||||
; return value: Length of src
|
||||
strlcpy:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
mov r9, rsi
|
||||
test rdx, rdx
|
||||
jz .quit
|
||||
@ -79,29 +68,20 @@ strlcpy:
|
||||
.quit:
|
||||
mov rdi, r9
|
||||
call strlen
|
||||
leave
|
||||
ret
|
||||
;----- strcat(char* dest, char* src) -----;
|
||||
; return value: pointer to dest
|
||||
strcat:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
mov r8, rdi
|
||||
call strlen
|
||||
add rdi, rax
|
||||
call strcpy
|
||||
mov rax, r8
|
||||
|
||||
leave
|
||||
ret
|
||||
;----- strcmp(char* str1, char* str2) -----;
|
||||
; return value: 0 if both strings are the same, otherwise index in array str1 where strings mismatch
|
||||
; returns -1 if str2 is longer than str1 and no difference was found before that happens
|
||||
strcmp:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
call strlen
|
||||
xor r10, r10
|
||||
.compareLoop:
|
||||
@ -115,25 +95,21 @@ strcmp:
|
||||
inc r10
|
||||
jmp .compareLoop
|
||||
.0f:
|
||||
mov rax, -1
|
||||
cmp byte [rsi], 0x0
|
||||
jne .quit
|
||||
xor rax, rax
|
||||
jmp .quit
|
||||
mov rax, -1
|
||||
cmp byte [rsi], 0x0
|
||||
jne .quit
|
||||
xor rax, rax
|
||||
jmp .quit
|
||||
|
||||
.mismatch:
|
||||
mov rax, r10
|
||||
mov rax, r10
|
||||
|
||||
.quit:
|
||||
leave
|
||||
ret
|
||||
;----- strclr(char* str) -----;
|
||||
; Replaces all characters of a string with \0 untill EOS is found
|
||||
; returns amount of changed characters
|
||||
strclr:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
call strlen
|
||||
mov rcx, rax
|
||||
mov rdx, rax
|
||||
@ -141,21 +117,14 @@ strclr:
|
||||
cld
|
||||
rep stosb
|
||||
mov rax, rdx
|
||||
|
||||
leave
|
||||
ret
|
||||
;----- strlclr(char* str, int size) -----;
|
||||
; Replaces characters of a string with \0, using arg size
|
||||
; <!> DANGEROUS FUNCTION, it might exceed string boundaries if used incorrectly. Use strclr() instead!
|
||||
; Function has no return value, rax will be 0 (0x0 stored in rax for opcode stosb)
|
||||
strlclr:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
mov rcx, rsi
|
||||
xor rax, rax
|
||||
cld
|
||||
rep stosb
|
||||
|
||||
leave
|
||||
ret
|
||||
|
Reference in New Issue
Block a user