made tolower not nuke your string (i think)

previously tolower would take your string and modify it but now it returns a new string that has been tolowered
This commit is contained in:
zombie maniac 2021-11-27 04:39:20 -05:00
parent 33a00bf2c2
commit 0428078991
2 changed files with 67 additions and 0 deletions

View file

@ -1,4 +1,5 @@
extern libz_strlen extern libz_strlen
extern malloc
global libz_tolower global libz_tolower
section .text section .text
@ -11,6 +12,32 @@ libz_tolower:
call libz_strlen call libz_strlen
mov r10, rax mov r10, rax
inc rax ;we do this because we need room for the null terminator
mov rdi, rax
push r11
push r10
call malloc ;spot to put the new string
pop r10
pop r11
;at this point r11 (hopfully) has the original string and rax has the new string home
push rax ;save rax for later
push rax ;save it twice so we can return the pointer
_mcopyloop:
mov r8b, [r11]
mov [rax], r8b
inc r11
inc rax
mov rsi, [r11] ;man i hope i can use rsi for anything and it wont nuke anything
cmp sil, 0
jnz _mcopyloop
pop r11 ;the loop below uses r11
xor rcx, rcx ;we do this to clear rcx incase it had garbage in it before xor rcx, rcx ;we do this to clear rcx incase it had garbage in it before
_loop: _loop:
@ -34,5 +61,7 @@ _endloop:
cmp rcx, r10 cmp rcx, r10
jle _loop jle _loop
pop rax ;returning rax (the pointer to the new string)
add rsp, 8 ;exit add rsp, 8 ;exit
ret ret

38
tolower_legacy.asm Normal file
View file

@ -0,0 +1,38 @@
extern libz_strlen
global libz_tolower
section .text
libz_tolower:
sub rsp, 8 ;enter
mov r11, rdi
call libz_strlen
mov r10, rax
xor rcx, rcx ;we do this to clear rcx incase it had garbage in it before
_loop:
;do loop things
mov r9, r11
add r9, rcx
mov r8b, [r9] ;this block here makes sure that our character is a capital letter and if its not a capital letter do nothing and return
cmp r8b, 90
ja _endloop
cmp r8b, 65
jb _endloop
add r8b, 32 ;make the letter capital
mov [r9], r8b
_endloop:
;end loop
inc rcx
cmp rcx, r10
jle _loop
add rsp, 8 ;exit
ret